DJANGOLEARN_IR Telegram 1096
سوال:
شما اسلایدر برای سایت تون چطوری می سازید؟

این پیشنهاد chatgpt بود:
اگه می‌خوای اسلایدرت خیلی انعطاف‌پذیر باشه، می‌تونی از GenericForeignKey استفاده کنی که به هر مدل وصل بشه (محصول، مقاله، دسته‌بندی و …).

from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType

class Slider(models.Model):
title = models.CharField(max_length=255, blank=True)
image = models.ImageField(upload_to="sliders/")
url = models.URLField(blank=True, null=True)

content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True, blank=True)
object_id = models.PositiveIntegerField(null=True, blank=True)
content_object = GenericForeignKey('content_type', 'object_id')

order = models.PositiveIntegerField(default=0)
is_active = models.BooleanField(default=True)

مزایا:

نهایت انعطاف‌پذیری: می‌تونی هر چیزی رو توی اسلایدر بذاری.
آینده‌نگر و تمیز.

معایب:
کار باهاش پیچیده‌تره.
برای خیلی از پروژه‌های معمولی زیادی Over-Engineering محسوب میشه.
11👍1🤔1



tgoop.com/djangolearn_ir/1096
Create:
Last Update:

سوال:
شما اسلایدر برای سایت تون چطوری می سازید؟

این پیشنهاد chatgpt بود:
اگه می‌خوای اسلایدرت خیلی انعطاف‌پذیر باشه، می‌تونی از GenericForeignKey استفاده کنی که به هر مدل وصل بشه (محصول، مقاله، دسته‌بندی و …).

from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType

class Slider(models.Model):
title = models.CharField(max_length=255, blank=True)
image = models.ImageField(upload_to="sliders/")
url = models.URLField(blank=True, null=True)

content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True, blank=True)
object_id = models.PositiveIntegerField(null=True, blank=True)
content_object = GenericForeignKey('content_type', 'object_id')

order = models.PositiveIntegerField(default=0)
is_active = models.BooleanField(default=True)

مزایا:

نهایت انعطاف‌پذیری: می‌تونی هر چیزی رو توی اسلایدر بذاری.
آینده‌نگر و تمیز.

معایب:
کار باهاش پیچیده‌تره.
برای خیلی از پروژه‌های معمولی زیادی Over-Engineering محسوب میشه.

BY جنگولرن


Share with your friend now:
tgoop.com/djangolearn_ir/1096

View MORE
Open in Telegram


Telegram News

Date: |

Clear According to media reports, the privacy watchdog was considering “blacklisting” some online platforms that have repeatedly posted doxxing information, with sources saying most messages were shared on Telegram. On June 7, Perekopsky met with Brazilian President Jair Bolsonaro, an avid user of the platform. According to the firm's VP, the main subject of the meeting was "freedom of expression." To edit your name or bio, click the Menu icon and select “Manage Channel.” Co-founder of NFT renting protocol Rentable World emiliano.eth shared the group Tuesday morning on Twitter, calling out the "degenerate" community, or crypto obsessives that engage in high-risk trading.
from us


Telegram جنگولرن
FROM American