Я хочу добавить в список, если регион содержит эту страну, ее отношение M2M между моделями Region и Country. я не могу получить атрибут кода страны, в котором говорится, что «двоеточие» ожидается. Что пропущено в условии if?Django many-to many filter field
views.py
notification = Notification.objects.filter(**condition). \
exclude(notification_user__in=users). \
order_by('notificationType__priority', '-start_date')
notifications = []
for n in notification:
print len(n.region.all())
if len(n.region.all())==0:
notifications.append(n)
else:
if (region.countries__in=country):
notifications.append(n)
Notififcation models.py
class Notification(models.Model):
title = models.CharField(max_length=75)
description = models.TextField()
start_date = models.DateTimeField()
end_date = models.DateTimeField()
application = models.ManyToManyField('Products.Application')
notificationType = models.ForeignKey(NotificationType)
url = models.URLField(null=True, blank=True)
region = models.ManyToManyField('Geolocations.Region', null=True, blank=True)
image = models.ImageField(null=True, blank=True)
user = models.ManyToManyField(User, through='Notification_User')
Geolocations models.py
class Country(models.Model):
code=models.CharField(max_length=2)
name=models.CharField(max_length=36)
def __unicode__(self):
return u'%s - %s' % (self.code, self.name)
class Meta:
verbose_name_plural="Countries"
class Region(models.Model):
name=models.CharField(max_length=10)
countries=models.ManyToManyField(Country)
пожалуйста исправить отступы – styvane
что была проблема поста, то identation является правильным –