I have 3 models as follows:
from django.db import models
from ckeditor.fields import RichTextField
# Create your models here.
class Species(models.Model):
scientific_name = models.CharField(max_length=50)
common_name = models.CharField(max_length=50, null=True, blank=True)
butterfly_image = models.ImageField(null=True, blank=True,
default="default.png")
# description = models.TextField(max_length=800, null=True, blank=True)
description = RichTextField(blank=True, null=True, default=None)
def __str__(self):
return self.scientific_name
class Meta:
ordering = ["scientific_name"]
=========================
from django.db import models
# Create your models here.
class Suppliers(models.Model):
name = models.CharField(max_length=60, null=True, blank=True)
phone = models.CharField(max_length=20)
email = models.EmailField(null=True, blank=True)
country = models.CharField(max_length=100, null=True, blank=True)
address = models.CharField(max_length=50, null=True, blank=True)
city = models.CharField(max_length=100, null=True, blank=True)
state = models.CharField(max_length=100, null=True, blank=True)
zipcode = models.CharField(max_length=15, null=True, blank=True)
class Meta:
ordering = ("name",)
def __str__(self):
return f"{self.name}"
=================
from django.db import models
from suppliers.models import Suppliers
from species.models import Species
# Create your models here.
class Shipments(models.Model):
yes_no_choice = ((True, "Yes"), (False, "No"))
name = models.OneToOneField(
Suppliers, null=True, blank=True, on_delete=models.SET_NULL
)
species = models.OneToOneField(
Species, null=True, blank=True, on_delete=models.SET_NULL
)
label = models.CharField(max_length=20)
received = models.IntegerField(default=0)
bad = models.IntegerField(default=0, blank=True, null=True)
non = models.IntegerField(default=0, blank=True, null=True)
doa = models.IntegerField(default=0, blank=True, null=True)
para = models.IntegerField(default=0, blank=True, null=True)
released = models.IntegerField(default=0, blank=True, null=True)
entered = models.BooleanField(choices=yes_no_choice, default=False)
updated = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)
def save(self, *args, **kwargs):
sub_quantity = self.bad + self.non + self.doa + self.para
self.released = self.received - sub_quantity
super().save(*args, **kwargs)
def __str__(self):
return str(self.name)
class Meta:
ordering = ["-created"]
======================================
I have a form to input shipment information:
{% extends 'base.html' %}
{% block title %}
Create/Update form
{% endblock title %}
{% block content %}
<div class="container-fluid pt-3">
<form action="" method="POST" class="row">
{% csrf_token %}
{{ form.as_p }}
<br>
<div class="pt-3">
<a href="{% url 'shipments:list-shipments' %}" class="btn
btn-primary">Back</a>
<input type="submit" value="Submit">
</div>
</form>
</div>
{% endblock content %}
PROBLEM:
- Shipments with this Name already exists.
Name: --------- BF.D. C.R.E.S E.B.N. ENT H.B.W. L.P.S.
T.E.H.
Species: --------- Actias luna Adelpha fessonia Agraulis
vanillae Anartia jatrophae Anteos chlorinde Appias drusilla
Archeaprepona
demophon Argema mimosae Ascia monuste Atrophaneura semperi Attacus
atlas Battus polydamas Biblis hyperia Brassolis isthmia Caligo
eurilochus Catonephele numilia Catopsilia pyranthe Cethosia cyane
Charaxes brutus Chilasa clytia Colobura dirce Consul fabius Danaus
gilippus Dione juno Dircenna dero Doleschalia bisaltide Dryadula
phaetusa Dryas iulia Eryphanis polyxena Eueides isabella Euphaedra
neophron Euploea phanaethrea Euxanthe wakefieldi Graphium angolanus
Greta oto Hamadryas amphinome Hebemoia glaucippe Heliconius
charitonius Heraclides anchisiades Hypna clymenestra Hypolimna
monteironis Hypolimnas bolina Idea leuconoe Junonia coenia Kallima
paraletka Lexia dirtea Limenitis archippus Lycorea cleobaea
Mechanitis
polymnia Melinaea ethra Memphis glycerium Methona confusa Morpho
peleides Myselia cyaniris Neptis hylas Nessaea aglaura Opisiphanes
tamarindi Opsiphanes cassina Pachliopta aristolochiae Panacea
procilla Papilio thoas Parides iphidamas Parthenos sylvia Phoebis
argante Precis atlites Prepona omphale Pterourus troilus
Rothschildea
lebeau Salamis anacardii Siproeta epaphus Tigridia acesta Tirumala
septentrionis Tithorea harmonia Troides rhadamantus Vindula dejone
Label:
Received:
Bad:
Non:
Doa:
Para:
Released:
Entered: Yes No
Back <http://127.0.0.1:8000/shipments/>
the supplier can have many species, many labels but if I try to add a
shipment with the same name I get an error saying the name already exists.
I need help trying to resolve this error. I am using postgreSQL 16 and it
gives me the same error.
I hope I gave you enough information here. Thank you
frank-
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAJbiy1DR6K%2BKX8j5tQOXw%3D8Od1ky3%2B67QjxRTfXqnPioY9rEPw%40mail.gmail.com.