In my view, the logic for extract should not be in the model. I would create a class specifically for data extractions. I am assuming that the _store does not DB saves to the Feed model, so that logic should not be inside Feed. A model should only perform operations on its own model. If you want to do operations on 2 different models, then have a helper function to do so or put it in the manager of the model, not the model itself.
In your case, since the data is stored in 2 different storages, I would put the logic in a helper class inside helpers.py.
# helpers.py
class Feeder(object):
def store(data):
# logix for storing to DB and any other storage.
@classmethoddef extract(cls, url, etag):
try:
@staticmethod#sub-logic here
return data, etag
except (.., ..) as ex:return data, etag
# handle exceptions
def extract_feed(feed)
# models.pydata, etag = Feeder.extract(feed.url, feel.etag)
feed.update_etag(etag)
feed.update_etag(etag)
class Feed():
def update_etag(self, etag):
if self.etag != etag:
self.etag = etag
self.save()
self.save()
Overall, it comes down to what makes sense to you. Once you accept a certain way of coding, it is meant to PREVENT YOU from doing guess work as to where you placed a specific logic. So when a bug happens and need to find the code, you are not opening/closing files to find the logic, you know where you put the logic.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/r9aBzSOftAMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment