How to get the id of an entry based on the name in Django?

i have created the following model in Django to store my groups in a database:

class Group(models.Model):
    name = models.CharField(max_length=1000)

now i would like to get the id of a group by its name in my views.py. How do I do that? with the Group.objects.get() method i can filter by name, but there i get the whole row without the id

You can query like this:

single_object=get_object_or_404(Group,name=any_name)
object_id=single_object.pk
Back to Top