kitek
kitek

Reputation: 117

Field name with a leading underscore in Model

Given a following model:

from django.db import models
class A(models.Model):
    _number = models.IntegerField()

Is it all right to have a leading underscore in a field name? What about use in Querysets?

Specifically I am concerned about the situation when there is another model B:

class B(models.Model):
    a = models.ForeignKey(A)

Then what would be the naming rule for queries?

B.objects.filter(a___number__in=(1,2,3)) or
B.objects.filter(a__number__in=(1,2,3))

Upvotes: 1

Views: 3577

Answers (1)

akaRem
akaRem

Reputation: 7638

Yes, it's ok.
Yes, in QuerySets you should use them with leading underscore:

A.objects.filter(_number__in=(1,2,3)).count()

Upvotes: 1

Related Questions