Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class New(models.Model):
- title = models.CharField(max_length=160, blank=True, null=True)
- thumbnail = models.ForeignKey('images.Images', on_delete=models.CASCADE, related_name='imagesrelate', null=True, blank=True)
- def __str__(self):
- return self.title
- -----------------------------------------------2 MODEL-----------------------------------------------------
- class Images(models.Model):
- image_name = models.CharField(max_length=50, blank=True, null=True)
- image_url = models.SlugField(max_length=100, unique=True)
- image_width = models.IntegerField(blank=True)
- image_height = models.IntegerField(blank=True)
- image_size = models.FloatField(blank=True)
- image_upload = models.ImageField(upload_to=user_directory_path, width_field='image_width', height_field='image_height')
- -----------------------------------------------Views-----------------------------------------------------
- from django.views.generic.detail import DetailView
- from news.models import New
- class NewsDetail(DetailView):
- model = New
- context_object_name = 'news'
- template_name = 'detailnews.html'
- slug_field = 'category'
- slug_url_kwarg = 'new'
- def get_context_data(self, **kwargs):
- context = super(NewsDetail, self).get_context_data(**kwargs)
- context['listnews'] = New.objects.order_by('-date_modification')[:5]
- return context
- -----------------------------------------------Template Not working-----------------------------------------------------
- {{news.images_thumbnail.image_url}} -->work
- {{news.images_thumbnail}} -->work
- {% for ima in news.imagesrelate.all %} -->not working
- {{ima.image_name}}
- {% endfor %}
- {% for ima in news.images_thumbnail.all %} --> not working
- {{ima.image_name}}
- {% endfor %}
- {% for ima in news.imagesrelate.all() %} --> TEMPLATE SYNTAX ERROR
- {{ima.image_name}}
- {% endfor %}
- {% for ima in news.images_thumbnail.all() %} --> TEMPLATE SYNTAX ERROR
- {{ima.image_name}}
- {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement