I'm struggling to get my models to enforce unique_together. We have the 
model below where it is possible to have a budget for a whole group (ie 
there is no break down for a particular sales rep) and therefore the 
sales_rep* *field will be left empty. However, it it possible to enter two 
identical values into the database via the Admin interface where the budget 
and years are the same while the sales_rep is empty.

I have seen some discussion on it in the archives, but wondered if there is 
a work around.

Cheers

ALJ

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

class Budget(models.Model):
    budget_type = models.ForeignKey(BudgetType, blank=False)
    sales_rep = models.ForeignKey(SalesRep, null=True, blank=True)
    year = models.IntegerField(blank=False)
    amount = models.FloatField(blank=False)
    
    class Meta:
        unique_together = (("budget_type","sales_rep", "year"),)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/SNZbLLHpJKwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to