小编Ana*_*ioN的帖子

Django - 如何为注册网站用户和非网站用户提供模型?

我有一个Trip模型,可以让许多参与者订阅一个特定的旅行和一个所有者.参与者是在网站上注册的用户,但我也希望能够在旅行中添加"离线"用户,在网站上没有帐户的用户,以便我可以跟踪所有用户.所有者和参与者链接到Userena用户配置文件(侧面问题:可能直接链接User会更好?但是如何在内联管理员中将full_name视为选择?)

class Trip(models.Model):
    name = models.CharField('trip name', max_length=200)
    type = models.ForeignKey(Category, related_name='categories')
    .
    .
    .
    slug = models.SlugField('trip slug', max_length=100)
    owner = models.ForeignKey(UserProfile, related_name='owner')
    participants = models.ManyToManyField(UserProfile, blank=True, null=True, related_name='participants')
    is_public = models.BooleanField("is visible?",db_index=True)

class ParticipationInline(admin.TabularInline):
    model = Trip.participants.through
    extra = 3

class TripAdmin(admin.ModelAdmin):

    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name in ('desc',):
            return db_field.formfield(widget=TinyMCE(
                attrs={'cols': 100, 'rows': 20},
                mce_attrs={'external_link_list_url': reverse('tinymce.views.flatpages_link_list')},
            ))
        return super(TripAdmin, self).formfield_for_dbfield(db_field, **kwargs)
    inlines = [
        ParticipationInline,
        ]
    exclude = ('participants',)
    prepopulated_fields = {"slug": …
Run Code Online (Sandbox Code Playgroud)

django django-admin django-authentication

5
推荐指数
1
解决办法
177
查看次数