1

I am using Django-Photologue in my project. I want to generate image title, slug automatically during save, if not specified. As a newbie in Django, I dont know how to do this. If I have to customize Django-photologue, then how should I do it?

Thank you for the response. I am willing to use the dumb method that you suggested. Want to do something like that. But how should I customize the photologue.Photo class?

Currently I have a Many2Many Key relationship in MatrimonyProfile with photologue.Photo like this

images = models.ManyToManyField("photologue.Photo", through="Image", blank=True)

and the Image through model

class Image(BaseModel):

profile = models.ForeignKey(MatrimonyProfile, on_delete=models.CASCADE)
photo = models.ForeignKey(
    "photologue.Photo", on_delete=models.CASCADE, related_name="+"
)

primary = models.BooleanField(default=False, blank=True)

Please help where and how to customize photologue.Photo to enter a default title

like now I have to enter the title enter image description here

1 Answers1

0

Generating slug automatically during save is pretty easy, as with the example below:

from django.utils.text import slugify

def save(self, *args, **kwargs):
        self.slug = slugify(self.title, allow_unicode=True)
        super().save(*args, **kwargs)

For image title, it's easier to add it manually (have it inputted by the user). Otherwise, if you want to generate the images' title automatically, you'll have to move on to pattern recognition and that is more than comlicated.

crimsonpython24
  • 2,223
  • 2
  • 11
  • 27
  • Slug is generated automatically, title is not. I want to generate title automatically, if the user misses to enter the title. Thank you for your response. – Bhawana Badlani Jul 21 '20 at 06:44
  • If you want the image title to be generated **accordingly**, you need to use image recognition and that's hard. The dumber but easier method is to pass a default title across all images by `title = models.CharField(default='default image title', ...)` – crimsonpython24 Jul 21 '20 at 08:29
  • Thank you. I have mentioned the problem in details above. – Bhawana Badlani Jul 22 '20 at 06:02
  • can I know how to pass this title? where should it be placed? how will I get access to the title field? – Bhawana Badlani Jul 23 '20 at 07:20
  • You can just place it in your model where you want this method to act on. You don't have to pass this title as there's the `self` argument, but just make sure you placed it after the title field – crimsonpython24 Jul 23 '20 at 07:42
  • but I am not creating a title field. I am using django-photologue app which has title field. – Bhawana Badlani Jul 24 '20 at 07:02
  • Sorry, then you might've needed to look things up as I never used that before. – crimsonpython24 Jul 24 '20 at 07:13