I want to do some custom validation:
class Products(models.Model):
Description = models.CharField(max_length=100)
Price = models.DecimalField(max_digits=5, decimal_places=2)
def __unicode__(self):
return "%s Eur %s" %(self.Description, self.Price)
class Orders(models.Model):
Name = models.CharField(max_length=40)
Product = models.ForeignKey(Products, default=None, null=True, blank=True)
class OrderForm(ModelForm):
class Meta:
model = Orders
def clean(self):
cleaned_data = super(OrderForm, self).clean()
P = cleaned_data.get("Product")
The problem I have is that P returns the unicode presentation of Products (like: Cableconnector Eur 6.75) I need however to get the Products id from the cleaned_data. Any idea how to accomplish this?
Ouch this was really easy….to get the id just call P.id