class AssignmentStaff(models.Model): staff_id=models.ForeignKey(Staff,on_delete=models.CASCADE()) dept_id=models.ForeignKey(Department,on_delete=models.CASCADE()) subj_id=models.ForeignKey(Subject,on_delete=models.CASCADE()) question=models.CharField(max_length=600) end_of_submission=models.DateTimeField(auto_now=False) # created_at=models.DateTimeField(auto_now=True) created_at=models.DateTimeField(auto_now_add=True)
class ServiceSubscribers(models.Model): id = models.IntegerField(primary_key=True) apartmentid = models.ForeignKey(Apartment, models.CASCADE(), db_column='ApartmentId') serviceid = models.ForeignKey(Services, models.CASCADE(), db_column='ServiceId') class Meta: db_table = 'ServiceSubscribers'
class MessageRecipients(models.Model): id = models.IntegerField(primary_key=True) messageid = models.ForeignKey('Messages', models.CASCADE(), db_column='MessageId') customerid = models.ForeignKey('User', models.CASCADE(), db_column='CustomerId') class Meta: db_table = 'MessageRecipients'
class Denegacion(models.Model): id = models.IntegerField(primary_key=True) numeroSolicitud = models.IntegerField() ciSolicitante = models.ForeignKey(CuentaUsuario, on_delete=models.CASCADE()) pais = models.ForeignKey(Pais, on_delete=models.CASCADE()) ciudad = models.ForeignKey(Ciudad, on_delete=models.CASCADE) tipoDnegacion = models.TextChoices('Alquilar', 'Rentar') comentarioDenegacion = models.CharField(max_length=100) administradorDenegador = models.ForeignKey(CuentaAdministrador, on_delete=models.CASCADE())
class CheckTrack(models.Model): request_choices = ( ('post', 'POST'), ('get', 'GET'), ('delete', 'DELETE'), ('put', 'PUT') ) check = models.ForeignKey(CheckDetails, on_delete=models.CASCADE()) request_type = models.CharField(max_length=10, choices=request_choices) prev_hitted_at = models.DateTimeField(auto_now_add=True) latest_hitted_at = models.DateTimeField(auto_now=True) latest_hit_by = models.ForeignKey(User, on_delete=models.CASCADE()) data_in_request_body = models.TextField(max_length=256)
class Serviceproviderservices(models.Model): id = models.IntegerField(primary_key=True) serviceproviderid = models.ForeignKey('Serviceproviders', models.CASCADE(), db_column='ServiceProviderId') price = models.DecimalField(db_column='Price', max_digits=18, decimal_places=0) serviceid = models.ForeignKey('Services', models.CASCADE(), db_column='ServiceId') class Meta: db_table = 'ServiceProviderServices'
class SolicitudRegistro(models.Model): pais = models.ForeignKey(Pais, on_delete=models.CASCADE()) ciudad = models.ForeignKey(Ciudad, on_delete=models.CASCADE) ciSolicitante = models.ForeignKey(CuentaUsuario, on_delete=models.CASCADE()) nroSolicitud = models.IntegerField() estadoSolicitud = models.TextChoices('Pendiente', 'Aprobada', 'Denegada') fechaSolicitud = models.DateField() horaSolicitud = models.TimeField() aprobador = models.ForeignKey(CuentaAdministrador, on_delete=models.CASCADE()) fechaGestion = models.DateField() horaGestion = models.TimeField() comentarioAprobador = models.CharField(max_length=100)
def _key_set_null_or_cascade(collector, field, sub_objs, using): """ on_delete callback for AS relation: - SET_NULL for keys that have a cert sensitive signing a TRC - CASCADE for all others Certificates include votes, that are references to certificates included in previous TRCs. The votes are specified via indices to the previous TRC `certificates` field (e.g. votes = [0, 3] means the first and 4th certificate in the list of certificates from the previous TRC). We need to preserve the possible voters in the previous TRCs, so making the `certificates` effectively immutable. Furthermore, we need to preserve keys and certificates for possible signers of future TRCs. These are sensitive and regular keys/certificates. In summary: we preserve keys whose certificates are part of TRCs. We use the callback on the Key.on_delete because Key is an intermediate model between Certificate and AS, and simplifies checking membership on the cert.trc_included. See also: - test_pki:CertificateTests.test_delete_while_sensitive_voted - pki.Certificate._pre_delete """ preserve = [ key for key in sub_objs if key.certificates.exclude(trc_included__isnull=True) ] others = [key for key in sub_objs if key not in preserve] if preserve: models.SET_NULL(collector, field, preserve, using) if others: models.CASCADE(collector, field, others, using)
class Imagen(): usuario = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE(), ) imagen = models.ImageField(upload_to='static/sitioI/', default='pic_folder/None/no-img.jpg')
class address(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE()) name = models.CharField(max_length=50) contact = models.CharField(max_length=12) pin = models.IntegerField() area = models.CharField(max_length=500) town = models.CharField(max_length=50)
class Movimiento(models.Model): subcategoria = models.ForeignKey(SubCategoria, on_delete=models.CASCADE()) fecha = models.DateField() nombre_dia = models.CharField(max_length=30, choices=properties.TIPO_DIA_SEMANA) nombre = models.CharField(max_length=200) valor = models.DecimalField(decimal_places=2, max_digits=10)
class VoteOption_2(models.Model): optionname = models.CharField(max_length=50, ) num = models.BigIntegerField(max_length=11, ) head = models.ForeignKey(VoteHeadline, on_delete=models.CASCADE()) def __str__(self): return self.optionname
class CheckDetails(models.Model): request_choices = ( ('post', 'POST'), ('get', 'GET'), ('delete', 'DELETE'), ('put', 'PUT') ) name = models.CharField(max_length=20) description = models.CharField(max_length=200) url = models.URLField(max_length=300) arrival_time = models.FloatField() waiting_time = models.FloatField() created_by = models.ForeignKey(User, on_delete=models.CASCADE()) updated_by = models.ForeignKey(User, on_delete=models.CASCADE()) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True)
class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) rating = models.IntegerField() game = models.ForeignKey(Games, on_delete=models.CASCADE()) def __str__(self): return self.first_name, self.last_name
class Obligaciones(models.Model): acredor_obligacion = models.ForeignKey(Acredor, on_delete=models.CASCADE()) saldo_obligacion = models.DecimalField() cuota_obligacion = models.DecimalField() tiempo = models.CharField(max_length=30, choices=properties.TIPO_TIEMPO) valor_tiempo = models.PositiveIntegerField() descripcion = models.CharField(max_length=500) tasa_obligacion = models.DecimalField(decimal_places=2)
def NON_POLYMORPHIC_CASCADE(collector, field, sub_objs, using): """ Cascade delete polymorphic models. Without this, a `django.db.utils.IntegrityError: FOREIGN KEY constraint failed` error occurs when deleting a project with more than one type of source. See https://github.com/django-polymorphic/django-polymorphic/issues/229#issuecomment-398434412 """ return models.CASCADE(collector, field, sub_objs.non_polymorphic(), using)
class UserPhone(models.Model): user = models.OneToOneField( User, on_delete=models.CASCADE(), related_name="phone", ) phone_number = models.CharField( max_length=12, verbose_name="номер телефона" )
class Bucketlist(models.Model): name = models.CharField(max_length=255, blank=False, unique=True) owner = models.ForeignKey('auth.User', related_name='bucketlist', on_delete=models.CASCADE()) date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) def __str__(self): return "{}".format(self.name)
class Quiz(models.Model): """ This class wll save quiz and its options """ question = models.CharField(max_length=500, blank=False) author = models.ForeignKey(User, on_delete=models.CASCADE()) creation_time = models.TimeField(auto_now_add=True) correct_option = models.IntegerField(max_length=1, blank=False) ordering = ["-creation_time"]
class Comment(models.Model): post = models.ForeignKey('post.Post', related_name='comments', on_delete=models.CASCADE()) name = models.CharField(max_length=120, verbose_name='Name') content = models.TextField(verbose_name="Commnet") created_date = models.DateTimeField(auto_now_add=True)
class Location(models.Model): id = models.IntegerField(db_column='LocationId', primary_key=True) name = models.CharField(unique=True, max_length=50, blank=True, null=True) address = models.CharField(max_length=100) customerid = models.ForeignKey('User', models.CASCADE(), db_column='CustomerId') specs = models.TextField(db_column='Specs') class Meta: db_table = 'Location'
class Messages(models.Model): id = models.AutoField(db_column='MessageId', primary_key=True) content = models.CharField(db_column='Content', max_length=256) type = models.CharField(db_column='Type', max_length=50) senderid = models.ForeignKey('User', models.CASCADE(), db_column='SenderId') attachments = models.TextField(db_column='Specs') class Meta: db_table = 'Messages'
class Topic(models.Model): """ 话题 """ content = models.CharField(max_length=200) created = models.DateTimeField(auto_now_add=True) user = models.ForeignKey('auth.User', related_name='topics_of', on_delete=models.CASCADE())
class ServiceProviders(models.Model): id = models.AutoField(db_column='ServiceProviderId', primary_key=True) serviceprovidername = models.CharField(db_column='ServiceProviderName', max_length=200) phone = models.CharField(db_column='Phone', max_length=50) email = models.CharField(db_column='Email', max_length=50) address = models.CharField(db_column='Address', max_length=50) active = models.BooleanField(db_column='Active') managerid = models.ForeignKey('User', models.CASCADE(), db_column='ManagerId') class Meta: db_table = 'ServiceProviders'
def NON_POLYMORPHIC_CASCADE(collector, field, sub_objs, using): """ This is a special cascade implementation to fix some delete errors when cascading polymorphic models. See: https://github.com/django-polymorphic/django-polymorphic/issues/229#issuecomment-398434412 :param collector: :param field: :param sub_objs: :param using: :return: """ return models.CASCADE(collector, field, sub_objs.non_polymorphic(), using)
def CASCADE_AND_AUTOUPDATE(collector: Any, field: Any, sub_objs: Any, using: Any) -> None: """ Like models.CASCADE but also informs the autoupdate system about the root rest element of the also deleted instance. """ elements = [] for sub_obj in sub_objs: root_rest_element = sub_obj.get_root_rest_element() elements.append( AutoupdateElement( collection_string=root_rest_element.get_collection_string(), id=root_rest_element.get_rest_pk(), )) inform_elements(elements) models.CASCADE(collector, field, sub_objs, using)
class Nurse(models.Model): name = models.CharField(max_length=200) surname = models.CharField(max_length=200) department = models.CharField(max_length=200) to_doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE()) def __str__(self): return '{}: {}'.format(self.id, self.name) def to_json(self): return { 'id': self.id, 'name': self.name, 'department': self.department, 'to_doctor': self.to_doctor }
class Apartment(models.Model): id = models.IntegerField(db_column='ApartmentId', primary_key=True) apartmentname = models.CharField(db_column='ApartmentName', unique=True, max_length=50) unitprice = models.DecimalField(db_column='UnitPrice', max_digits=12, decimal_places=2, blank=True, null=True) locationid = models.ForeignKey('Location', models.CASCADE(), db_column='LocationId') specification = models.TextField(db_column='Specification') class Meta: db_table = 'Apartment'
class Game(models.Model): first_player = models.ForeignKey(User, # Foreign Key to User Model (django comes w/ default User class) related_name="games_first_player") second_player = models.ForeignKey(User, related_name="games_second_player") start_time = models.DateTimeField(auto_now_add=True) last_active = models.DateTimeField(auto_now_add=True class Move(models.Model): x = models.IntegerField() # Coordinates where move was made x = models.IntegerField() # Coordinates where move was made comment = models.CharField(max_length=300, blank=True) # Player can make comment w/ every move by_first_player = models.BooleanField() # Determines who made the move game=models.ForeignKey(Game, on_delete=models.CASCADE()) # If game gets deleted so do all the moves connected
def _key_set_null_or_cascade(collector, field, sub_objs, using): """ on_delete callback for AS relation: - SET_NULL for keys with usage==TRC_VOTING_OFFLINE - CASCADE for all others This "trick" is required to be able to use voting offline keys for the creation of a new TRC after an AS has been deleted. """ voting_offline = [ key for key in sub_objs if key.usage == Key.TRC_VOTING_OFFLINE ] others = [key for key in sub_objs if key.usage != Key.TRC_VOTING_OFFLINE] if voting_offline: models.SET_NULL(collector, field, voting_offline, using) if others: models.CASCADE(collector, field, others, using)