Created
February 21, 2018 07:10
-
-
Save dura0ok/228ce38dfc15f2643c96a9e85f9b83c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% extends 'base.html' %} | |
| {% for cat in cat %} | |
| <p>{{ cat.title }}</p> | |
| {% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Category(models.Model): | |
| name = models.CharField(max_length=200) | |
| def __str__(self): | |
| return self.name | |
| # test | |
| class Post(models.Model): | |
| author = models.ForeignKey('auth.User', on_delete=models.CASCADE) | |
| title = models.CharField(max_length=200) | |
| category = models.ForeignKey(Category) | |
| text = models.TextField() | |
| image = models.ImageField(upload_to='img') | |
| created_date = models.DateTimeField( | |
| default=timezone.now) | |
| published_date = models.DateTimeField( | |
| blank=True, null=True) | |
| def publish(self): | |
| self.published_date = timezone.now() | |
| self.save() | |
| def __str__(self): | |
| return self.title |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getcat(request, id): | |
| cat = Post.objects.filter(category=id) | |
| Categories = Category.objects.all() | |
| context = { | |
| 'cat': cat, | |
| 'category': Categories | |
| } | |
| return render(request, 'cat.html', context=context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment