mardi 6 mai 2014

Django - choisissez queryset pour limit_choices_to basé sur les champs de l'objet - Stack Overflow


I am trying to limit the choices of a foreign field to those other objects who look like the object self.


I've tried this:


class Model1(models.Model):
entry = models.ForeignKey(Model2, limit_choices_to='get_limit_choices_to')
number = IntegerField()

def get_limit_choices_to(self):
return Model2.objects.filter(expenditure_type=self.expenditure_type)

class Model2(models.Model):
number = IntegerField()

but I get the error


_filter_or_exclude() argument after ** must be a mapping, not str

I don't know if limit_choices_to is the right way to do this. Maybe I should choose the queryset in a or the views.


The error says that limit_choices_to='get_limit_choices_to' is a wrong way to refer to the method, but how can I refer to the method correctly? I can't use


limit_choices_to=lambda: {'model1_set': self}

nor


limit_choices_to=lambda: {'number': number}

I am using Django 1.7.



I am trying to limit the choices of a foreign field to those other objects who look like the object self.


I've tried this:


class Model1(models.Model):
entry = models.ForeignKey(Model2, limit_choices_to='get_limit_choices_to')
number = IntegerField()

def get_limit_choices_to(self):
return Model2.objects.filter(expenditure_type=self.expenditure_type)

class Model2(models.Model):
number = IntegerField()

but I get the error


_filter_or_exclude() argument after ** must be a mapping, not str

I don't know if limit_choices_to is the right way to do this. Maybe I should choose the queryset in a or the views.


The error says that limit_choices_to='get_limit_choices_to' is a wrong way to refer to the method, but how can I refer to the method correctly? I can't use


limit_choices_to=lambda: {'model1_set': self}

nor


limit_choices_to=lambda: {'number': number}

I am using Django 1.7.


Related Posts:

0 commentaires:

Enregistrer un commentaire