Tuesday, September 25, 2018

Re: Allow a limit_choices_to callable to accept the current model instances object

There's a ticket with that feature request: https://code.djangoproject.com/ticket/25306

On Tuesday, September 25, 2018 at 6:25:38 PM UTC-4, Ochui Princewill wrote:
Hello, 

Am current working on a project and i want to filter the content of a ForeignkeyField base on the current model object

class Subscription(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
plan = models.ForeignKey(Plan, on_delete=models.CASCADE)
expires = models.DateField()
created_at = models.DateTimeField(auto_now_add=True)

class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, editable=False)
subscription = models.ForeignKey(Subscription, limit_choices_to={'user_id': settings.AUTH_USER_MODEL}, on_delete=models.SET_NULL, null=True, blank=True)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5abc1695-ae5b-45c2-ac8f-c73d7c2d0be7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment