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: |

Developing social channels based on exchanging a single message isn’t exactly new, of course. Back in 2014, the “Yo” app was launched with the sole purpose of enabling users to send each other the greeting “Yo.” Select: Settings – Manage Channel – Administrators – Add administrator. From your list of subscribers, select the correct user. A new window will appear on the screen. Check the rights you’re willing to give to your administrator. Select “New Channel” Telegram Android app: Open the chats list, click the menu icon and select “New Channel.” fire bomb molotov November 18 Dylan Hollingsworth yau ma tei
from us


Telegram جنگولرن
FROM American