Django relationships

28 views
Skip to first unread message

Murad

unread,
Jun 24, 2021, 5:24:22 PM6/24/21
to Django users
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

David Crandell

unread,
Jun 26, 2021, 1:28:19 AM6/26/21
to Django users
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

David Crandell

unread,
Jun 26, 2021, 1:31:13 AM6/26/21
to Django users
the way I manage my inventory system is keep all devices in one table and flag assigned or unassigned like you're trying to do. Each is then assigned to a locationID.

On Thursday, June 24, 2021 at 4:24:22 PM UTC-5 murad...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages