Python Forum
<title> django page title dynamic and other field (not working)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
<title> django page title dynamic and other field (not working)
#2
Problem solved.

views.py
def view_album(request):
    album = Album.objects.all().order_by('creato')
    return render(request, 'album.html', {'album': album})


def view_photo(request,  album_slug):
    photo = Photo.objects.filter(album__slug=album_slug)
    album = Album.objects.filter(slug=album_slug).order_by('creato')
    return render(request, 'album_detail.html', {'photo': photo, 'album': album})
models.py
from django.db import models
from django.utils.text import slugify
from django.urls import reverse
STATO = (
    (0,"Bozza"),
    (1,"Publico")
)

class Pages(models.Model):

    id = models.AutoField(primary_key=True)
    autore = models.ForeignKey(
        "auth.User",
        on_delete=models.CASCADE,
    )
    titolo = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, unique=True)
    contenuto = models.TextField()
    stato = models.IntegerField(choices=STATO, default=0)
    creato = models.DateTimeField(auto_now_add=True)
    modificato = models.DateTimeField(auto_now= True)

    def __str__(self):
        return self.titolo

    def get_absolute_url(self):
        return reverse('pages', kwargs={"id": self.id,'slug': self.slug})
        
    def save(self, *args, **kwargs):
        self.slug = slugify(self.titolo)
        super().save(*args, **kwargs)
        
    class Meta:
        ordering = ['-creato']
Reply


Messages In This Thread
RE: <title> django page title dynamic and other field (not working) - by lemonred - Nov-04-2021, 08:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Not getting Info(Title) yrstruly 1 1,775 Jan-25-2023, 10:24 PM
Last Post: snippsat
  Parsing html page and working with checkbox (on a captcha) straannick 17 11,377 Feb-04-2021, 02:54 PM
Last Post: snippsat
  Getting a list in dynamic page probottpric 1 1,804 Oct-12-2020, 01:11 AM
Last Post: Larz60+
  css not working in Django mp3909 3 3,777 Jul-06-2020, 02:34 PM
Last Post: mp3909
  [Django] css file is not applying to the page SheeppOSU 1 3,091 May-09-2020, 06:54 AM
Last Post: menator01
  use Xpath in Python :: libxml2 for a page-to-page skip-setting apollo 2 3,652 Mar-19-2020, 06:13 PM
Last Post: apollo
  Django Two blocks of dynamic content on one page iFunKtion 5 4,437 Jul-04-2019, 02:31 AM
Last Post: noisefloor
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,339 Jun-30-2019, 12:21 AM
Last Post: scidam
  pull streams from Twitch with a keyword in title maddensplayers 1 2,179 Feb-18-2019, 03:19 AM
Last Post: SheeppOSU
  Sorting getting off, when I switch page Django 1.11 m0ntecr1st0 0 1,993 Feb-12-2019, 06:40 PM
Last Post: m0ntecr1st0

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020