Re: Model design question
Thanks Mike, that is what I was originally planning to do but realized there would be situations where that wouldn't do exactly what I wanted. For example, if there is a business that only has the strategy 'wholesale' assigned, using ForeignKey would still allow me to assign a different strategy to a division. I was hoping to find a solution where the strategy for a division is constrained by the strategies assigned to its respective business.
On Thursday, May 17, 2012 5:55:11 PM UTC-7, Mike Dewhirst wrote:
On 18/05/2012 7:02am, oneroler wrote:--
> I'm trying to setup my first app and I'm trying to figure out the best
> way to have constraints on a particular field (strategy for class
> Division noted below). Below is the basic model structure. What I
> would like is for the strategy under a Division to be constrained to
> the strategies selected for the Business. A business may have many
> strategies, but a division will only have one (but it should only be
> one selected for the business). Any help on this would be
> appreciated. Thanks, Sam
>
> class Strategy(models.Model):
> name = models.CharField(max_length=200)
>
> #name would be something like retail, wholesale, etc
>
> class Business(models.Model):
> name = models.CharField()
> strategy = models.ManyToManyField(Strategy)
>
> class Division(models.Model):
> business = models.ForeignKey(Business)
> name = models.CharField()
> strategy = ???
Try ...
strategy = models.ForeignKey(Strategy)
>
> --
> 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/-/ .sunwQb8Ft0cJ
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en .
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/-/-hITt8lS1f0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home