Friday, June 25, 2021

Re: Django relationships

You'll have to define "in_use" as a models.BooleanField()

I would have base class Devices

and have Stock and Assign inherit from those

On Thursday, June 24, 2021 at 4:24:22 PM UTC-5 murad...@gmail.com wrote:
Hi Django developers,
i am new in Python,

i want to develop a simple app stock management.

can you give me a brief idea how to add device to stock if it hasnt assigned to employee

i have below models

class Device(models.Model):
STATUS = ( 
('in use', in use),
 ('available', 'available')
)
    status =models.Charfield(choices=STATUS, max_length=32)
    name = models.Charfield(max_length=32)


class Employee(models.Model):
    name = models.Charfield(max_length=32)


class Assign(models.Model):
   notebook =  models.ForeignKey(' Device  ', on_delete=models.CASCADE)
    subscriber = models.ForeignKey('Employee', on_delete=models.CASCADE)


class Stock(models.Model):
    pass


I want if device is already has subscribers then aply its status to 'in_use' and remove it from Stock model and if device status is available then move it to Stock

--
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c2d782c8-0a8c-41ac-b471-8075aab01e14n%40googlegroups.com.

No comments:

Post a Comment