Answer the question
In order to leave comments, you need to log in
How to update a unique field in ModelAdmin with a non-unique value on bulk data update?
There is a model with a unique field filled with unique values.
class MyModel(models.Model):
uniqfield = models.IntegerField('Уникальное поле', unique=True)
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
list_display = ('uniqfield',)
def save_model(self, request, obj, form, change):
try:
obj.save()
except
# соообщение об не уникальности вставляемых значений
pk=1, uniqfield=1
pk=2, uniqfield=2
я в форме редактирования на странице меняю их местами и хочу получить:
pk=1, uniqfield=2
pk=2, uniqfield=1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question