vendredi 21 février 2020

Admin site is not working and throwing Error about one of the views but views are still working django

This is the Error it is throwing Plz check

I am trying to get the posts related to certain tag and I did that but when I accessing admin panel it is showing on posts_tag view, I am not able to debug that why it is related to admin panel

    class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User,on_delete=models.CASCADE)
    tags = models.ManyToManyField('Tag',through='Tagged')
    class Meta:
        ordering=['-date_posted']
    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('post-detail',kwargs={'pk':self.pk})
`class Tag(models.Model):
    name=models.CharField(max_length=50)
    posts = models.ManyToManyField('Post',through='Tagged')

    def __str__(self):
        return self.name
class Tagged(models.Model):
    post = models.ForeignKey(Post,on_delete=models.CASCADE)
    tag = models.ForeignKey(Tag,on_delete=models.CASCADE)

urls.py

urlpatterns=[
path('',views.post_list,name='blog-home'),
path('<tag>/',views.post_tag,name='blog-tag'),
path('post/<int:pk>/',views.post_detail,name='post-detail'),
path('post/new/',views.post_create,name='post-create'),
path('post/<int:pk>/update/',views.post_update,name='post-update'),
path('post/<int:pk>/delete/',views.post_delete,name='post-delete'),
path('about/',views.about,name='blog-about')]

views.py

def post_tag(request,tag):
    t=Tag.objects.get(name=tag).posts.all()
    tags = Tagged.objects.all()
    return render(request,'blog/home.html',context={'posts':posts,'tags':tags})`



Aucun commentaire:

Enregistrer un commentaire