DJANGOLEARN_IR Telegram 1098
می دونستید ممکنه unique_together در آینده توی جنگو منسوخ بشه؟

البته از جنگو 2.2 به بعد داره میگه در آینده ممکنه منسوخ بشه 😁

لینک:
https://docs.djangoproject.com/en/5.2/ref/models/options/#django.db.models.Options.unique_together

خود داکیومنت جنگو گفته بهتره از UniqueConstraint استفاده کنید:

لینک:
https://docs.djangoproject.com/en/5.2/ref/models/constraints/#django.db.models.UniqueConstraint

یه مثال:
فرض کن میخواهیم ترکیب محصول و رنگ فقط یکی باشه، قبلا اینجوری می نوشتیم:
class Meta:
unique_together = ('product', 'color')

توی UniqueConstraint اینجوریه:
class Meta:
constraints = [
models.UniqueConstraint(fields=['product', 'color'], name='unique_product_option')
]


تازه میتونیم بگیم در شرایطی خاص این حالت فعال باشه.
خودتون زحمت بکشید condition رو توی لینکی که دادم سرچ کنید.
قابلیت های دیگه ای هم داره، که بازم خودتون...

و من الله التوفیق
115👍3



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

می دونستید ممکنه unique_together در آینده توی جنگو منسوخ بشه؟

البته از جنگو 2.2 به بعد داره میگه در آینده ممکنه منسوخ بشه 😁

لینک:
https://docs.djangoproject.com/en/5.2/ref/models/options/#django.db.models.Options.unique_together

خود داکیومنت جنگو گفته بهتره از UniqueConstraint استفاده کنید:

لینک:
https://docs.djangoproject.com/en/5.2/ref/models/constraints/#django.db.models.UniqueConstraint

یه مثال:
فرض کن میخواهیم ترکیب محصول و رنگ فقط یکی باشه، قبلا اینجوری می نوشتیم:

class Meta:
unique_together = ('product', 'color')

توی UniqueConstraint اینجوریه:
class Meta:
constraints = [
models.UniqueConstraint(fields=['product', 'color'], name='unique_product_option')
]


تازه میتونیم بگیم در شرایطی خاص این حالت فعال باشه.
خودتون زحمت بکشید condition رو توی لینکی که دادم سرچ کنید.
قابلیت های دیگه ای هم داره، که بازم خودتون...

و من الله التوفیق

BY جنگولرن




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

View MORE
Open in Telegram


Telegram News

Date: |

Don’t publish new content at nighttime. Since not all users disable notifications for the night, you risk inadvertently disturbing them. Just as the Bitcoin turmoil continues, crypto traders have taken to Telegram to voice their feelings. Crypto investors can reduce their anxiety about losses by joining the “Bear Market Screaming Therapy Group” on Telegram. Joined by Telegram's representative in Brazil, Alan Campos, Perekopsky noted the platform was unable to cater to some of the TSE requests due to the company's operational setup. But Perekopsky added that these requests could be studied for future implementation. The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be: Administrators
from us


Telegram جنگولرن
FROM American