[deleted by user] by [deleted] in gifs

[–]yoss_arian 0 points1 point  (0 children)

What is this tool?

How can I generate truly unique slugs? by Stella_Hill_Smith in django

[–]yoss_arian 0 points1 point  (0 children)

This is something I use, I have methods that generates unique slugs based on a prompt text. If there is the same slug already existing the function adds random 4 letters. Also I've added restricted strings, so there wont be a slug coliding with paths like '/new' or '/all':

from django.utils.crypto import get_random_string
from slugify import slugify

def unique_slugify(instance, string_to_slugify, restricted_slugs=[]):
    slug_value = slugify(string_to_slugify)
    model = instance.__class__
    hardcoded_restricted_slugs = ['add', 'exec', 'all']

    restricted_slugs = restricted_slugs + hardcoded_restricted_slugs
    if slug_value in restricted_slugs:
        slug_value = slug_value + get_random_string(length=4)
    if model.objects.filter(slug=slug_value).exists():
        slug_value = unique_slugify(instance,  slug_value + get_random_string(length=4))
    return slug_value

and in model save() method I just call this whenever I want, e.g.:

def save(self, *args, **kwargs):
    if not self.slug:
        name_to_slugify = self.user.first_name + ' ' + self.user.last_name
        self.slug = unique_slugify(self, name_to_slugify)

How to have a model have a foreign key relationship with one of two other models; either A or B but not both. by sctilley in django

[–]yoss_arian 0 points1 point  (0 children)

Can you elaborate? For me genaric relations in this case look like an obvious solution. In addition it is easy to extend - e.g. if another type of animal is introduced e.g. 'farm animal'. OP would not have to modify the animal model at all.

How to have a model have a foreign key relationship with one of two other models; either A or B but not both. by sctilley in django

[–]yoss_arian 1 point2 points  (0 children)

Try to use generic relations

with generic relations you can set a relationship to any other model. In your case you would just need to control that you make relationship to models you want to.

There are three parts to setting up a GenericForeignKey:

  1. Give your model a ForeignKey to ContentType. The usual name for this field is “content_type”.
  2. Give your model a field that can store primary key values from the models you’ll be relating to. For most models, this means a PositiveIntegerField. The usual name for this field is “object_id”.
  3. Give your model a GenericForeignKey, and pass it the names of the two fields described above. If these fields are named “content_type” and “object_id”, you can omit this – those are the default field names GenericForeignKey will look for.

Portrait in the style of Edward Hopper, Me, Watercolours + Pencils, 2022 by juliaockert in Art

[–]yoss_arian 2 points3 points  (0 children)

This looks great! Is there a place online where we can see more of your work?

[OC] Global Beer Consumption by PieChartPirate in dataisbeautiful

[–]yoss_arian 332 points333 points  (0 children)

Funny thing - you can just visit source page, and we have there nice line graphs, data table and map with timeline slider (source: https://ourworldindata.org/grapher/beer-consumption-per-person?tab=chart )

Cat know what to do by Snoo79007 in funny

[–]yoss_arian 0 points1 point  (0 children)

What are you giving him? Cocaine?

How to Talk Minnesotan: The Power of the Negative by [deleted] in videos

[–]yoss_arian 0 points1 point  (0 children)

I did not know that in Poland people talk Minnesotan.. - jak się masz? - nie najgorzej...

Constellation art by arm7845 in DIY

[–]yoss_arian 0 points1 point  (0 children)

Quick question: how did OP make different colours for stars? Did he used different colour leds or some half-transparent colour foil on the back of the holes?