D
D
dimas75252018-09-02 22:41:03
Django
dimas7525, 2018-09-02 22:41:03

How to display objects using Query Set?

There is a model that stores the id of cars (car) that may be of interest to the user in the cid field. How to display a list of cars (car) on the page by these id?

class ProbableCar(models.Model):
    user = models.ManyToManyField(allauth_app_settings.USER_MODEL, editable=False)
    cid = models.PositiveIntegerField()

class Car(models.Model):
     user = models.ForeignKey(allauth_app_settings.USER_MODEL,
                             on_delete=models.CASCADE, default="", editable=False)
    model = models.CharField(max_length=128, blank=True, null=True, default=" ")
    type = models.CharField(max_length=3, blank=True, null=True, default="m",  choices=TYPE_CHOICES)
    buydate = models.DateField(blank=True, null=True, default= " ")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-09-03
@immaculate

class ProbableCar(models.Model):
    user = models.ForeignKey(settings.USER_MODEL, on_delete=models.CASCADE)
    cid = models.ForeignKey('Car', on_delete=models.CASCADE)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question