Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lógica para update #67

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions basedosdados_api/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,24 +330,32 @@ def get_success_url(self):
return reverse("datasetdetail", kwargs={"pk": self.object.pk})


class UpdateFrequency(BdmModel):
class Update(BdmModel):
id = models.UUIDField(primary_key=True, default=uuid4)
entity = models.ForeignKey(
"Entity", on_delete=models.CASCADE, related_name="update_frequencies"
"Entity", on_delete=models.CASCADE, related_name="updates"
)
number = models.IntegerField()
frequency = models.IntegerField()
lag = models.IntegerField(blank=True, null=True)
last = models.DateTimeField(blank=True, null=True)

graphql_nested_filter_fields_whitelist = ["id"]

def __str__(self):
return f"{str(self.number)} {str(self.entity)}"

class Meta:
db_table = "update_frequency"
verbose_name = "Update Frequency"
verbose_name_plural = "Update Frequencies"
db_table = "update"
verbose_name = "Update"
verbose_name_plural = "Updates"
ordering = ["number"]

def clean(self) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfagundes tá correta a escrita dessa validação?

if self.entity.category.slug != "datetime":
raise ValidationError(
"Entity's category is not in category.slug = `datetime`."
)
return super().clean()

class Table(BdmModel):
id = models.UUIDField(primary_key=True, default=uuid4)
Expand All @@ -370,8 +378,12 @@ class Table(BdmModel):
partner_organization = models.ForeignKey(
"Organization", on_delete=models.CASCADE, related_name="partner_tables"
)
update_frequency = models.ForeignKey(
"UpdateFrequency", on_delete=models.CASCADE, related_name="tables"
update = models.ForeignKey(
"Update",
on_delete=models.CASCADE,
related_name="tables",
null=True,
blank=True,
)
pipeline = models.ForeignKey(
"Pipeline", on_delete=models.CASCADE, related_name="tables"
Expand Down Expand Up @@ -589,8 +601,12 @@ class RawDataSource(BdmModel):
license = models.ForeignKey(
"License", on_delete=models.CASCADE, related_name="raw_data_sources"
)
update_frequency = models.ForeignKey(
"UpdateFrequency", on_delete=models.CASCADE, related_name="raw_data_sources"
update = models.ForeignKey(
"Update",
on_delete=models.CASCADE,
related_name="raw_data_sources",
null=True,
blank=True,
)
area_ip_address_required = models.ManyToManyField(
"Area", related_name="raw_data_sources", blank=True
Expand Down Expand Up @@ -619,8 +635,12 @@ class InformationRequest(BdmModel):
status = models.ForeignKey(
"Status", on_delete=models.CASCADE, related_name="information_requests"
)
update_frequency = models.ForeignKey(
"UpdateFrequency", on_delete=models.CASCADE, related_name="information_requests"
update = models.ForeignKey(
"Update",
on_delete=models.CASCADE,
related_name="information_requests",
null=True,
blank=True,
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
Expand Down