0

I want to create Django model for below data: How can I create array for activity_periods and members ?

{
    "ok": true,
    "members": [{
            "id": "W012A3CDE",
            "real_name": "Egon Spengler",
            "tz": "America/Los_Angeles",
            "activity_periods": [{
                    "start_time": "Feb 1 2020  1:33PM",
                    "end_time": "Feb 1 2020 1:54PM"
                },
                {
                    "start_time": "Mar 1 2020  11:11AM",
                    "end_time": "Mar 1 2020 2:00PM"
                },
                {
                    "start_time": "Mar 16 2020  5:33PM",
                    "end_time": "Mar 16 2020 8:02PM"
                }
            ]
        },
        {
            "id": "W07QCRPA4",
            "real_name": "Glinda Southgood",
            "tz": "Asia/Kolkata",
            "activity_periods": [{
                    "start_time": "Feb 1 2020  1:33PM",
                    "end_time": "Feb 1 2020 1:54PM"
                },
                {
                    "start_time": "Mar 1 2020  11:11AM",
                    "end_time": "Mar 1 2020 2:00PM"
                },
                {
                    "start_time": "Mar 16 2020  5:33PM",
                    "end_time": "Mar 16 2020 8:02PM"
                }
            ]
1
  • Can you please post where you are so far, have you checked django documentation on creating models in general? I hope you find the help you need, if you have any code please post it or try editing your question to be more specific Commented Apr 5, 2020 at 14:57

1 Answer 1

1

This is typically a use-case for ForeignKey

from timezone_field import TimeZoneField

class Member(models.Model):
   id = models.CharField()
   real_name = models.CherField()
   tz = TimeZoneField(default='Europe/London')

class Period(models.Model):
   member = models.ForeignKey(Member, on_delete=models.CASCADE)
   start = models.DateTimeField()
   end = models.DateTimeField()

By this, you will be able to write Period-specific methods (ex : compute time range)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.