django model get_absolute_url not working -
i have seen example of using above method directly on model instance book. not working actually. method removed in latest versions? here code.
in [24]: django_tag out[24]: <tag: django> in [22]: django_tag.get_absolute_url() --------------------------------------------------------------------------- attributeerror traceback (most recent call last) <ipython-input-22-bde20b3ec098> in <module>() ----> 1 django_tag.get_absolute_url() attributeerror: 'tag' object has no attribute 'get_absolute_url'
i looked dir
function. don't show such method exists. i'm using django v. 1.11.
in [25]: dir(django_tag) out[25]: ['doesnotexist', 'multipleobjectsreturned', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_check_column_name_clashes', '_check_field_name_clashes', '_check_fields', '_check_id_field', '_check_index_together', '_check_local_fields', '_check_long_column_names', '_check_m2m_through_same_relationship', '_check_managers', '_check_model', '_check_model_name_db_lookup_clashes', '_check_ordering', '_check_swappable', '_check_unique_together', '_do_insert', '_do_update', '_get_field_display', '_get_next_or_previous_by_field', '_get_next_or_previous_in_order', '_get_pk_val', '_get_unique_checks', '_meta', '_perform_date_checks', '_perform_unique_checks', '_save_parents', '_save_table', '_set_pk_val', '_state', 'blog_posts', 'check', 'clean', 'clean_fields', 'date_error_message', 'delete', 'from_db', 'full_clean', 'get_deferred_fields', 'id', 'name', 'objects', 'pk', 'prepare_database_save', 'refresh_from_db', 'save', 'save_base', 'serializable_value', 'slug', 'startup_set', 'unique_error_message', 'validate_unique']
models.py
class tag(models.model): name = models.charfield(max_length=31, unique=true) slug = models.slugfield(unique=true, help_text='a label url config.') def __str__(self): return self.name class meta: ordering = ['name']
please read docs
class tag(models.model): name = models.charfield(max_length=31, unique=true) slug = models.slugfield(unique=true, help_text='a label url config.') def __str__(self): return self.name def get_absolute_url(self): django.urls import reverse return reverse('appname.views.viewname', args=[self.slug]) class meta: ordering = ['name']
wiki
Comments
Post a Comment