Skip to content

Instantly share code, notes, and snippets.

@dura0ok
Created February 21, 2018 07:10
Show Gist options
  • Select an option

  • Save dura0ok/228ce38dfc15f2643c96a9e85f9b83c9 to your computer and use it in GitHub Desktop.

Select an option

Save dura0ok/228ce38dfc15f2643c96a9e85f9b83c9 to your computer and use it in GitHub Desktop.
{% extends 'base.html' %}
{% for cat in cat %}
<p>{{ cat.title }}</p>
{% endfor %}
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
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