如您所见,我只想显示用户所属的组。
models.py
如何在管理员的个人资料信息中显示群组?
class UserProfile(models.Model):
ERKEK = 'E'
KADIN = 'K'
OTHER = 'O'
CINSIYET = ((ERKEK, 'ERKEK'), (KADIN, 'KADIN'), (OTHER, 'DİĞER'))
PUBLIC = 'P'
FOLLOWING = 'F'
VISIBLE = ((PUBLIC, 'PUBLIC'), (FOLLOWING, 'FOLLOWING'))
user = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name = "Kullanıcı")
new_group_name = models.ManyToManyField(Group, max_length=20, verbose_name="Grup", blank=True)
telefon_numarasi = models.CharField(max_length=11, verbose_name="Telefon Numarası", blank=True)
cinsiyet = models.CharField(max_length=1, default=3, choices=CINSIYET, verbose_name="Cinsiyet", blank=True)
hakkinda = models.TextField(max_length=500, verbose_name="Hakkında", blank=True)
dogum_tarihi = models.DateField(verbose_name="Doğum Tarihi", null=True, blank=True)
profil_photo = models.ImageField(upload_to=upload_to, verbose_name="Profil Resmi", default='profile_photo/user_default.png', null=True, blank=False)
visible = models.CharField(choices=VISIBLE, max_length=1, default=1, verbose_name="Profil Görüntüsü")
class Meta:
verbose_name_plural='Kullanıcı Bilgileri'
def get_full_name_or_username(self):
if self.user.get_full_name():
return self.user.get_full_name()
return self.user.username
def __str__(self):
return "%s Profile"%(self.get_full_name_or_username())
def create_user_profile(instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(receiver=create_user_profile, sender=User)
forms.py
当我在网站上编辑个人资料信息时,如何显示我的论坛?
class UserProfileForm(forms.ModelForm):
ERKEK = 'E'
KADIN = 'K'
OTHER = 'O'
CINSIYET = ((ERKEK, 'ERKEK'), (KADIN, 'KADIN'), (OTHER, 'DİĞER'))
cinsiyet = forms.CharField(widget=forms.Select(choices=CINSIYET))
new_group_name = forms.ModelChoiceField(queryset=Group.objects.all(), required=True)
hakkinda = forms.CharField(widget=forms.Textarea, max_length=500, label='Hakkında', required=False)
dogum_tarihi = forms.DateField(widget=DatePickerInput(), required=False)
telefon_numarasi = forms.CharField(max_length=11, label='Telefon Numarası', required=False)
class Meta:
model = User
fields = ['username', 'new_group_name', 'first_name', 'last_name', 'email', 'dogum_tarihi', 'telefon_numarasi', 'cinsiyet', 'hakkinda']
def __init__(self, *args, **kwargs):
super(UserProfileForm, self).__init__(*args, **kwargs)
for field in self.fields:
self.fields[field].widget.attrs={'class':'form-control'}
self.fields['hakkinda'].widget.attrs['rows']=10
self.fields['hakkinda'].widget.attrs['cols']=10
尽管我们进行了研究,但找不到解决方案。拜托,您能给我解决方案吗?