I'm creating a project in Django and I'm having trouble, I'm trying to get the ID of objects in my database, but when I run it the object seems to not have an ID. Here is my model:
from __future__ import unicode_literals
from django.db import models
class film(models.Model):
filmName = models.CharField(primary_key=True, max_length=120)
quotient = models.FloatField()
rating = models.FloatField()
gross = models.IntegerField()
star = models.CharField(max_length=120)
releaseDate = models.DateField()
def __unicode__(self):
return self.filmName
and in my view:
objects = film.objects.filter(filmName__startswith=letter)
for object in objects:
print object.id
I get an error saying id does not exist and I'm not sure why
You've explicitly told Django that filmName is the primary key, so there is no separate ID.
It's not usually a good idea to do this, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With