gpt4 book ai didi

django - Django新闻通讯应用

转载 作者:行者123 更新时间:2023-12-03 13:25:26 27 4
gpt4 key购买 nike

django是否有任何新闻通讯应用程序,允许用户订阅/取消订阅新闻通讯?我想要一个易于使用且可通过Django管理员进行管理的应用。

最佳答案

也许吧,也许不是。拥有在时事通讯(无论如何想象)与订阅者(用户或用户的外键或firstName / lastName / emailAddress / password)之间具有多对多关联的应用程序并不难。

您的模型将如下所示:

from django.db import models
from django.contrib.auth.models import User

class Subscriber(models.Model):
user = models.ForeignKey(User)
email = models.EmailField()

def __unicode__(self):
return "User %s" % (self.user.username, )

@models.permalink
def get_absolute_url(self):
return ('subscriber', None, {'object_id' : self.id})

class Meta:
ordering = [ "id" ]

class Newsletter(models.Model):
name = models.CharField(max_length=80)
subscribers = models.ManyToManyField('Subscriber')
# .... Other stuff

def __unicode__(self):
return "Newsletter %s" % (self.name, )

@models.permalink
def get_absolute_url(self):
return ('newsletter', None, {'object_id' : self.id})

class Meta:
ordering = [ "id" ]


您的urls.py将如下所示:

from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template

urlpatterns = patterns('',
url(r'^subscriber/(?P<object_id>\d+)/$', views.subscriberview, name='subscriber_view'),
url(r'^newsletter/(?P<object_id>\d+)/$'', views.newsletterview,name='newsletter_view'),
url(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT}),
)


这足以使您前进吗?

关于django - Django新闻通讯应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1267930/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com