python - Getting specific fields of a model in another, via relationships between them -
i working django-smart-selects deploy specific forms fields based in options selected in same forms. have following models:
session, have manytomany relationship metrics
session model
class session(models.model): corporal_structures = models.foreignkey(singlebodysegment) movement = chainedmanytomanyfield( movements, chained_field = 'corporal_structures', chained_model_field = 'corporal_segments' ) metrics = models.manytomanyfield(metrics, blank=true) date_session_begin = models.datetimefield(default=timezone.now()) date_session_end = models.datetimefield(default=timezone.now()) observations = models.textfield(blank=false )
metrics model
class metrics(models.model): name = models.charfield(max_length=255, blank=true) equation = models.charfield(max_length=255, blank=true) min_value = models.decimalfield(max_digits=5,decimal_places=3) max_value = models.decimalfield(max_digits=5,decimal_places=3) def __str__(self): return "%s" % self.name due manytomany relationship, in sessions form (in django admin) can see list of metrics of metrics model, can see name attribute of metrics instance in form
i want not name attribute, want equation, min_value , max_value attributes part of metrics model
in model/table metrics create metrics instance, when create instance of session model, should denote metrics value session instance, correspondent native fields such as:
how can other fields of metrics model , have them available in session form?
if associated metrics , sessions models manytomany relationship, should useful want, really?
i have been thinking doubt more of relationships topics , django orm instead django-smart-select application. don't know if in previous affirmation
any orientation appreciated.
just change magic function __str__ present inside metrics model below.
def __str__(self): return "{},{},{}".format(self.name, self.min_value, self.max_value) this method overrides default __str__ function. may modify return value according needs.


Comments
Post a Comment