Django-admin one of the field must be filled in django-models
up vote
0
down vote
favorite
Hello I have model like
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
Since I'm using the django admin as a back-end controller of the data stored in my model I want to make either one of them to not be null
for example the user must either fill a
or either fill b
or both
to be filled, but if both
are empty must throw an error
django django-models django-admin
add a comment |
up vote
0
down vote
favorite
Hello I have model like
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
Since I'm using the django admin as a back-end controller of the data stored in my model I want to make either one of them to not be null
for example the user must either fill a
or either fill b
or both
to be filled, but if both
are empty must throw an error
django django-models django-admin
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Hello I have model like
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
Since I'm using the django admin as a back-end controller of the data stored in my model I want to make either one of them to not be null
for example the user must either fill a
or either fill b
or both
to be filled, but if both
are empty must throw an error
django django-models django-admin
Hello I have model like
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
Since I'm using the django admin as a back-end controller of the data stored in my model I want to make either one of them to not be null
for example the user must either fill a
or either fill b
or both
to be filled, but if both
are empty must throw an error
django django-models django-admin
django django-models django-admin
asked Nov 9 at 8:59
Kostadin Slavov
752218
752218
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You can add custom validation like this
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
def clean(self):
if not (self.a and self.b):
raise ValidationError(....)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You can add custom validation like this
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
def clean(self):
if not (self.a and self.b):
raise ValidationError(....)
add a comment |
up vote
2
down vote
accepted
You can add custom validation like this
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
def clean(self):
if not (self.a and self.b):
raise ValidationError(....)
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You can add custom validation like this
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
def clean(self):
if not (self.a and self.b):
raise ValidationError(....)
You can add custom validation like this
class mymodel(models.Model):
a = models.CharField(blank=True, null=True, max_length=255)
b = models.CharField(blank=True, null=True, max_length=255)
c = models.CharField(blank=False, null=False, max_length=255)
def clean(self):
if not (self.a and self.b):
raise ValidationError(....)
answered Nov 9 at 9:05
a_k_v
637112
637112
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222583%2fdjango-admin-one-of-the-field-must-be-filled-in-django-models%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown