I'm incorporating django-fsm into a Django project containing a model that will include a number of state transitions, like so:
from django_fsm import FSMField, transition
class Record(models.Model):
state = FSMField(default='new')
@transition(
field=state,
source=['new', 'flagged'],
target='curated',
custom=dict(
verbose="Curate as trustworthy",
explanation=("This record is deemed trustworthy."),
url_path="curate/",
#url_path=reverse("record-curate", kwargs={"pk": self.pk}),
),
)
def curate(self, by=None, description=None):
"""This record is deemed trustworthy.
"""
return
def get_curate_url(self):
return reverse("record-curate", kwargs={"pk": self.pk})
I am now at the point of wanting to connect up some views to activate transition changes for an instance of Record. In the example above, url_path
is a hardcoded path to the view whereas I would like to dynamically generate the path value based upon the pk
attribute of the parent Record
instance. I understand that I can't access self
within the decorator, but is there any way for me to get access to an attribute value of the class instance of the decorated curate
method?
For reference, here is the URL to the django-fsm project: https://github.com/viewflow/django-fsm#custom-properties