Форум сайта python.su
2
Есть модель:
class UserAbout(models.Model): user = models.ForeignKey(User, related_name='UserAboutToUser', unique=True) about = models.TextField(max_length = 1000, blank=True, null=True, unique=False) family = models.TextField(max_length = 1000, blank=True, null=True, unique=False) why = models.TextField(max_length = 1000, blank=True, null=True, unique=False) trust = models.TextField(max_length = 1000, blank=True, null=True, unique=False) hobby = models.TextField(max_length = 1000, blank=True, null=True, unique=False) job = models.TextField(max_length = 1000, blank=True, null=True, unique=False) politic = models.CharField(max_length = 100, blank=True, null=True, unique=False) book = models.TextField(max_length = 1000, blank=True, null=True, unique=False) film = models.TextField(max_length = 1000, blank=True, null=True, unique=False) music = models.TextField(max_length = 1000, blank=True, null=True, unique=False) class UserAboutForm(ModelForm): class Meta: model = UserProfile exclude = ('user',)
def UserProfileEdit(request, offset):
mainProfile = User.objects.get(username = offset[0])
About = UserAbout.objects.filter(user = mainProfile).values(
'about',
'family',
'why',
'trust',
'hobby',
'job',
'politic',
'book',
'film',
'music',)
form = UserAboutForm(instance = About[0])
return render_to_response ("main.html", {
'form': form,
}, context_instance = RequestContext(request))
Отредактировано SorrowFuck (Ноя. 12, 2012 13:53:54)
Офлайн
568
Не передавать в инит формы словарь, очевидно же. А метод .values() возвращает как раз список словарей.
Почему не
UserAbout.objects.filter(user = mainProfile) form = UserAboutForm(instance = About[0])
Офлайн
2
FishHookСобственно я так пробовал, но вот, что меня смутило это то, что вместо UserAboutForm возвращается UserProfileForm пустая естественно.
Не передавать в инит формы словарь, очевидно же. А метод .values() возвращает как раз список словарей.Почему не
class UserProfile(models.Model): user = models.ForeignKey(User, related_name='UserProfileToUser', unique=True) age = models.IntegerField() rating = models.FloatField() avatar = models.ImageField(blank=True, null=True, upload_to="avatars") citizenship = models.CharField(max_length=30, blank=True, null=True) country = models.CharField(max_length=30, blank=True, null=True) city = models.CharField(max_length=30, blank=True, null=True) VERIFICATION_CHOICES = ( (u'Н', u'Низкий'), (u'С', u'Средний'), (u'В', u'Высокий'), ) verification = models.CharField(max_length=1, choices=VERIFICATION_CHOICES, blank=True, null=True) class UserProfileForm(ModelForm): class Meta: model = UserProfile exclude = ('user', 'verification',)
Офлайн
568
Ну теперь вообще не понятно,
В форме
model = UserProfile
About = UserAbout.objects....
Офлайн
2
FishHookА слона-то я и не заметил. Спасибо.
Ну теперь вообще не понятно, В форме
Офлайн