On Sep 18, 2016 4:01 AM, "Ali khan" <alipathan123...@gmail.com> wrote:
> I have two different apps and applying filters by ForeignKey and as
newbie I am not able to understand how it works.
> My Order App:
>> class Order(models.Model):
>> status = models.CharField(max_length=120,
>> cart = models.ForeignKey(Cart)
>> user = models.ForeignKey(UserCheckout, null=True)
>> billing_address = models.ForeignKey(UserAddress,
>> shipping_address = models.ForeignKey(UserAddress,
>> shipping_total_price = models.DecimalField(max_digits=50,
>> order_total = models.DecimalField(max_digits=50, decimal_places=2, )
>> order_id = models.CharField(max_length=20, null=True, blank=True)
>> paymethod = models.CharField(max_length=120, choices=CHOICES,
>> My seller's app:
>> class Seller(models.Model):
>> user = models.ForeignKey(settings.AUTH_USER_MODEL)
>> managers = models.ManyToManyField(settings.AUTH_USER_MODEL,
>> active = models.BooleanField(default=False)
>> timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
> I am trying to keep all the filters in mixin.py so I can call and use as
per need. Following is the function and I can't filter orders by user who
is the seller.
> def sold(self):
> user = self.Seller.user
> order = Seller.objects.filter(user=user)
> return order
There is no relationship between the Order and the Seller, so you can't
filter the Order's based on a specific Seller. You probably want to add a
FK from Order to Seller.
> Please advise.
I'm a bit confused. Are you trying to filter based on kwarg arguments
captured through your urls.py, or via GET/POST parameters provided by a
form, or just trying to limit the scope of available objects that a
specific user can see?
Everything you've shown here is a model (not an app). Filtering is
generally performed either in the views, and/or in the model managers. Can
you provide the views and possibly mixins?
If you have existing filters that aren't working, please post up that code
along with any trace backs.
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 post to this group, send email to firstname.lastname@example.org.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
For more options, visit https://groups.google.com/d/optout.