Django rest-framework with durable_rules

Viewed 266

I am trying to integrate durable_rules with my django restframework apis

I need some guidance as to how to proceed with this

Lets say, I have a class school , class student, class location

class School(models.Model):
schoolname = models.CharField(max_length=200)

class Location(models.Model):
locationname = models.CharField(max_length=200)

class Student(models.Model):
school = models.ForeignKey(School)
location = models.ForeignKey(Location)
studentname = models.CharField(max_length=200)
fees = models.IntegerField()

Now, I want to make rules saying

if (schoolname = 'ABC' and location = 'xyz') then update fees = 1000
if (schoolname = 'SDS' and location = 'sdfs') then update fees = 200

How do I do this with durable_rules? My question if more on where do I write the code for it, in views or serializers.

Any sample code would be of great help

Thanks

Now based on the school

1 Answers
class Student(models.Model):
  school = models.ForeignKey(School)
  location = models.ForeignKey(Location)
  studentname = models.CharField(max_length=200)
  fees = models.IntegerField()

  #You can overide the Student Model save method 
  def save(self, *args, **kwargs):
    if self.schoolname == 'ABC' and self.location = 'xyz':
        self.fees = 1000
    if self.schoolname = 'SDS' and self.location = 'sdfs':
        self.fees = 200
    super(Student, self).save(*args, **kwargs)

##you can also use django signals post save and pre save.

Related