{"id":718,"date":"2018-03-24T08:39:00","date_gmt":"2018-03-24T08:39:00","guid":{"rendered":"https:\/\/codenerix.com\/?p=718\/"},"modified":"2023-04-06T06:47:22","modified_gmt":"2023-04-06T06:47:22","slug":"gencreate-genupdate-gendetail-and-gendelete","status":"publish","type":"post","link":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/","title":{"rendered":"GenCreate, GenUpdate, GenDetail and GenDelete"},"content":{"rendered":"\n<p>\ud83c\uddea\ud83c\udde6&nbsp;Leer en Espa\u00f1ol, \u201c<a href=\"https:\/\/www.juanmitaboada.com\/codenerix-gencreate-genupdate-gendetail-gendelete\/\"><strong>GenCreate, GenDetail, GenUpdate y GenDelete<\/strong><\/a>\u201c<\/p>\n\n\n\n<p>In the last article, we described <strong><a href=\"https:\/\/codenerix.com\/en\/genlist\/\">GenList<\/a><\/strong> to start using <strong><span style=\"color: #343433;\"><strong><a href=\"https:\/\/github.com\/codenerix\/django-codenerix\"><span style=\"color: #343433;\">CODE<\/span><span style=\"color: #70a8e0;\">NERIX<\/span><\/a><\/strong><\/span><\/strong> listings. The time has come to see how to create, view, update and delete the information on those listings.<\/p>\n\n\n\n<p>In this article, we will talk about<strong> GenCreate, GenDetail, GenUpdate, and GenDelete<\/strong>.<\/p>\n\n\n\n<p>First, each one inherits from its <strong>Django<\/strong> equivalent, such that <strong>GenCreate<\/strong> inherits from <strong>CreateView<\/strong>, <strong>GenUpdate<\/strong> from <strong>UpdateView<\/strong>, <strong>GenDetail<\/strong> from <strong>DetailView<\/strong>, and <strong>GenDelete<\/strong> from <strong>DeleteView<\/strong>.<\/p>\n\n\n\n<p>Let&#8217;s see first what the example model that we are going to use, &#8220;<strong>Contact<\/strong>&#8220;, would look like:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class Contact(CodenerixModel):\n    first_name = models.CharField(verbose_name=_(u'Name(s)'), max_length=128)\n    last_name = models.CharField(verbose_name=_(u'Last name'), max_length=128, blank=True, null=True)\n    alias = models.CharField(verbose_name=_(u'Alias'), max_length=32, blank=True, null=True)\n    organization = models.CharField(verbose_name=_(u'Organization'), max_length=64, blank=True, null=True)\n    borndate = models.DateField(verbose_name=_(u'Borndate'), blank=True, null=True)\n    address = models.TextField(verbose_name=_(u'Address'), blank=True, null=True)\n    created_by = models.ForeignKey(User, verbose_name=_(u'Created by'), on_delete=models.CASCADE, related_name='contacts')\n\n    def __fields__(self, info):\n        return (\n            ('first_name', _(u'Name(s)')),\n            ('last_name', _(u'Last name')),\n            ('alias', _(u'Alias')),\n            ('organization', _(u'Organization')),\n        )<\/pre>\n\n\n\n<p>and your &#8220;<strong>ContactForm<\/strong>&#8221; form, which will inherit from <strong>GenModelForm<\/strong>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GenModelForm:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from codenerix.forms import GenModelForm\n\nclass ContactForm(GenModelForm):\n\n    class Meta:\n        model = Contact\n        exclude = ['created_by']\n\n    def __groups__(self):\n        return [\n            (\n                _(u'Principal'), 6,\n                ['first_name', 6],\n                ['last_name', 6],\n                ['alias', 6],\n            ),\n            (\n                _(u'Principal'),\u00a06,\n               \u00a0['organization',\u00a06],\n               \u00a0['borndate',\u00a06],\n               \u00a0['address',\u00a06],\n           \u00a0)\n        ]\n\n    @staticmethod\n    def __groups_details__():\n        return [\n            (\n                _(Contact'), 12,\n                ['alias', 12],\n                ['organization', 12],\n                ['borndate', 12],\n                ['address', 12],\n            )\n        ]<\/pre>\n\n\n\n<p>Since <strong>GenModelForm<\/strong> is <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">new<\/mark><\/strong>, I will only point out that it inherits from <strong>Django<\/strong>&#8216;s <strong>BaseModelForm<\/strong> and that the only thing new compared to a <strong>Django<\/strong> <strong>ModelForm<\/strong> is the groups. Groups are the definition of how we want a form to look on the screen and are built with a list of tuples containing:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Field block <strong>title<\/strong><\/li>\n\n\n\n<li><strong>Width<\/strong> in <strong>Bootstrap<\/strong> <strong>columns<\/strong><\/li>\n\n\n\n<li><strong>N-tuples<\/strong> refer to the fields of the form where each tuple will have as its first element the <strong>name of the field<\/strong> that will go in that position and its <strong>width in Bootstrap columns<\/strong>. There are more elements in these tuples that I will explain in future posts.<\/li>\n<\/ol>\n\n\n\n<p>In this way, the form indicated above would be as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"543\" src=\"https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_form-1-1024x543.png\" alt=\"\" class=\"wp-image-719\" srcset=\"https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_form-1-1024x543.png 1024w, https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_form-1-980x520.png 980w, https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_form-1-480x255.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p>Where the fields are self-validated on the user&#8217;s browser side and thus greatly reduce server calls. Said form explained to your group would be as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"543\" src=\"https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_form_schema-1024x543.png\" alt=\"\" class=\"wp-image-720\" srcset=\"https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_form_schema-1024x543.png 1024w, https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_form_schema-980x520.png 980w, https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_form_schema-480x255.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p>Let&#8217;s discover the details of these 4 views that work like their Python counterparts with the same attributes and methods as these but offer much more functionality.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GenModify<\/h2>\n\n\n\n<p>To talk to <strong>GenCreate<\/strong> and <strong>GenUpdate<\/strong>, we first have to talk about <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">GenModify<\/mark><\/strong>, which manages the operation when a record is created and updated. It is not a view that we will use directly. However, this class will indirectly be part of GenCreate and GenUpdate, respectively. Since the creation and update of the record vary in minimal matters: the form coincides, and the validations are the same, the GenModify class is in charge of managing how GenCreate and GenUpdate act in each case, preloading the form with the record that is being edited in a GenUpdate and both cases storing the changes (<strong>new<\/strong> or <strong>updated<\/strong>) in the database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Table of attributes allowed by <strong>GenModify<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Attribute<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">angular_delete<\/mark><\/strong><\/td><td>Name of the angular method that will receive the action when the \u201c<strong>Delete<\/strong>\u201d button is pressed, by default \u201c<strong>delete<\/strong>\u201d.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">angular_delete = \"delete\"<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">angular_submit<\/mark><\/strong><\/td><td>Name of the angular method that will receive the action when the form is submitted, by default, \u201c<strong>submit<\/strong>\u201d.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">angular_submit = \"submit\"<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">buttons_bottom<\/mark><\/strong><\/td><td>Show action buttons below the form, and defaults to <strong>True<\/strong>.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">buttons_bottom = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">buttons_top<\/mark><\/strong><\/td><td>It shows the action buttons above the form and defaults to <strong>True<\/strong>.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">buttons_bottom = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">extends_base<\/mark><\/strong><\/td><td>It contains the base template path from which the List template will inherit. It usually goes to a \u201c<strong>base\/base.html<\/strong>\u201c, but by changing this variable, you can tell it to load a different file to offer the user a different environment experience.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">extends_base = \"base\/base.html\"<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">form_groups<\/mark><\/strong><\/td><td>The group to apply to this view (equivalent to <strong>__groups__<\/strong>) can be a method or a function.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">form_ngcontroller<\/mark><\/strong><\/td><td>By specifying this attribute, an extra controller will be added to the form that will serve to include extra functionalities accessory to the standard form.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">form_ngcontroller = \"nuevo_controlador\"<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">__groups__<\/mark><\/strong><\/td><td>The group to apply to this view (equivalent to <strong>form_groups<\/strong>) can be a method or a function.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">hide_foreignkey_button<\/mark><\/strong><\/td><td>When this attribute is activated, the option to work the fields with external relationships through modal windows is shown. By default this attribute is False. In the following example, you can see 2 fields, &#8220;<strong>Brand<\/strong>&#8221; (Marca) and &#8220;<strong>Category<\/strong>&#8221; (Categor\u00eda), in which since there is no element selected in &#8220;Brand&#8221;, the system shows a &#8220;<strong>+<\/strong>&#8221; symbol to add a new record since it assumes that none of those in the list is valid for the user to fill in that field. If there is a selected element, the system displays a &#8220;<strong>pencil<\/strong>&#8221; in order to allow the selected element to be edited. Both &#8220;<strong>creation<\/strong>&#8221; and &#8220;<strong>editing<\/strong>&#8221; occur in a modal window.<br><br><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"104\" class=\"wp-image-723\" style=\"width: 250px;\" src=\"https:\/\/codenerix.com\/wp-content\/uploads\/2022\/06\/codenerix_foreign_keys.png\" alt=\"\"><br><br>Sometimes we do not want to see these buttons because we do not want the user to access these modal windows, either because we do not want them visually or because they do not have permissions or they are not developed. Marking this attribute as \u201c<strong>True<\/strong>\u201d will hide these buttons.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">hide_foreignkey_button = False<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">json<\/mark><\/strong><\/td><td>It will return a response in <strong>JSON<\/strong> format, by default, <strong>True<\/strong>.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">json = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">json_details<\/mark><\/strong><\/td><td>It will trigger verbose responses in <strong>JSON<\/strong> responses, by default, <strong>True<\/strong>.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">json_details = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">linkback<\/mark><\/strong><\/td><td>It shows the \u201c<strong>Back\u201d <\/strong>button and defaults to <strong>True<\/strong>.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">linkback = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">linkdelete<\/mark><\/strong><\/td><td>It shows the \u201c<strong>Delete<\/strong>\u201d button and defaults to True. This attribute is only available in <strong>editing forms<\/strong> (it is not enabled for creation forms since there is no record to delete).<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">linkdelete = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">linksavehere<\/mark><\/strong><\/td><td>It shows the \u201c<strong>Save Here<\/strong>\u201d button, which defaults to <strong>True<\/strong>.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">linksavehere = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">linksavenew<\/mark><\/strong><\/td><td>It shows the \u201c<strong>Save and New<\/strong>\u201d button, which defaults to <strong>True<\/strong>.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">linksavenew = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">show_details<\/mark><\/strong><\/td><td>At the end of the execution of the form, the system will try to return to the list, however, if <strong>show_details<\/strong> is activated, the system will go to the details view instead of the list.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">show_details = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">show_internal_name<\/mark><\/strong><\/td><td>When set to True, it will display a title on the form. By default, it is activated in normal forms and deactivated in \u201c<strong>modal<\/strong>\u201d forms.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">show_internal_name = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">success_url_keys<\/mark><\/strong><\/td><td>A correctly completed form always responds with a valid status and also with a <strong>JSON<\/strong> dictionary containing at least 2 keys:<br><ul><li><strong>__pk__<\/strong> which includes the PK of the created or updated object<strong>__str__<\/strong> that contains the representation in text format of said created or updated object.<\/li><\/ul>The response system always overwrites these 2 keys. However, if other keys are included in the <strong>success_url_keys<\/strong> attribute, they will also be included in the form response, and this data can be used to obtain extra information on the object created\/modified or on its status. end of the operation requested to the form.<br><br>The <strong>success_url_keys<\/strong> attribute should be a list of strings that can have the following format:<br><ul><li><strong>&#8220;key&#8221;:<\/strong> will be evaluated as if it were <strong>&#8220;key:key&#8221;\u201ckey1:key2\u201d:<\/strong> will be evaluated as <strong>answer[key1]=object.key2<\/strong><\/li><\/ul><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">success_url_keys = [\"id\",\"name:title\"]<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">title<\/mark><\/strong><\/td><td>If show_internal_name is activated, a title will be shown, and the title will be calculated automatically by mixing the action, which can be \u201c<strong>Adding<\/strong>\u201d or \u201c<strong>Editing<\/strong>\u201d, and the form&#8217;s name. However, when modifying this attribute, the content of this attribute will be displayed directly, preventing it from being auto-calculated.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">title = _(\"Nuevo t\u00edtulo para el formulario\")<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>These attributes are available in both the create and edit views.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GenCreate and GenCreateModal<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from codenerix.views import GenCreate, GenCreateModal\nclass ContactCreate(GenCreate):\n    model = Contact\n    form_class = ConctactForm\nclass ContactCreateModal(GenCreateModal, ContactCreate):\n    pass<\/pre>\n\n\n\n<p><strong>GenCreate<\/strong> is a view that inherits <strong>Django<\/strong>&#8216;s <strong>CreateView<\/strong> from GenModify. At its minimum, it needs the same fields as <strong>CreateView<\/strong>. These are &#8220;<strong>model<\/strong>&#8221; and &#8220;<strong>form_class<\/strong>&#8220;. Since <strong>GenCreate<\/strong> inherits from <strong>GenModify<\/strong>, its features will also be available.<\/p>\n\n\n\n<p>To the views to which we include a <strong>GenCreateModal<\/strong>, we will get the render to prepare the result to be displayed in a modal window. In the background, what actually happens is that it adds the <strong>Bootstrap<\/strong> modal window marquee and ends the rendering at that point.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GenUpdate and GenUpdateModal<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from codenerix.views import GenUpdate, GenUpdateModal\nclass ContactUpdate(GenUpdate):\n    model = Contact\n    form_class = ContactForm\nclass ContactUpdateModal(GenUpdateModal, ContactUpdate):\n    pass<\/pre>\n\n\n\n<p><strong>GenUpdate<\/strong> is a view that inherits <strong>Django<\/strong>&#8216;s <strong>UpdateView<\/strong> from GenModify. At its minimum, it needs the same fields as <strong>UpdateView. These<\/strong> are &#8220;<strong>model<\/strong>&#8221; and &#8220;<strong>form_class<\/strong>&#8220;. Since <strong>GenUpdate<\/strong> inherits from <strong>GenModify<\/strong>, <strong>GenModify<\/strong>&#8216;s features will also be available.<\/p>\n\n\n\n<p>In the views to which we include a <strong>GenUpdateModal<\/strong>, we will get the render to prepare the result to be displayed in a modal window. In the background, what actually happens is that it adds the <strong>Bootstrap<\/strong> modal window marquee and ends the rendering at that point.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GenDetail and GenDetailModal<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from codenerix.views import GenDetail, GenDetailModal\nclass ContactDetail(GenDetail):\n    model = Contact\n    groups = ContactForm.__groups_details__()\nclass ContactDetailModal(GenDetailModal, ContactDetail):\n    pass<\/pre>\n\n\n\n<p><strong>GenDetail<\/strong> is a view that inherits <strong>Django<\/strong>&#8216;s <strong>DetailView<\/strong> and <strong>GenModify<\/strong>, used to display data from an object. At its minimum, it needs the same fields as the <strong>DetailView. These<\/strong> are \u201c<strong>model<\/strong>\u201d and \u201c<strong>form_class<\/strong>\u201c.<\/p>\n\n\n\n<p>To the views to which we include a <strong>GenDetailModal<\/strong>, we will get the render to prepare the result to be displayed in a modal window. In the background, what actually happens is that it adds the <strong>Bootstrap<\/strong> modal window marquee and ends the rendering at that point.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Table of attributes allowed by GenDetail<\/h3>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Attribute<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">exclude_fields<\/mark><\/strong><\/td><td>A list of fields will be excluded when rendering the object&#8217;s data. <strong>GenDetail<\/strong> will always show all the fields of the object, it will use (just like forms) the groups to show the information organized by them, and the rest of the fields will go consecutively at the end of the group. However, if a field appears in the <strong>exclude_fields<\/strong> list, it will not be displayed in the details view.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">exclude_fields = [\"contact\", \"price\"]<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">extra_context<\/mark><\/strong><\/td><td>It is a dictionary that contains extra information that will be sent to the template.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">groups<\/mark><\/strong><\/td><td>They work like the <strong>GenCreate<\/strong> and <strong>GenUpdate<\/strong> view groups.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">linkback<\/mark><\/strong><\/td><td>A list of fields will be excluded when rendering the object&#8217;s data. <strong>GenDetail<\/strong> will always show all the fields of the object. It will use (just like forms) the groups to show the information organized by them, and the rest of the fields will go consecutively at the end of the group. However, if a field appears in the <strong>exclude_fields<\/strong> list, it will not be displayed in the details view.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">exclude_fields = [\"contact\", \"price\"]<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">linkedit<\/mark><\/strong><\/td><td>It shows the \u201c<strong>Edit<\/strong>\u201d button and defaults to <strong>True<\/strong>.<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">linkedit = True<\/code><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">linkdelete<\/mark><\/strong><\/td><td>It shows the \u201c<strong>Delete<\/strong>\u201d button and defaults to <strong>True<\/strong>. This attribute is only available in editing forms (it is not enabled for creation forms since there is no record to delete).<br><br><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">linkdelete = True<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GenDelete<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from codenerix.views import GenDelete\n\nclass ContactDelete(GenDelete):\n    model = Contact<\/pre>\n\n\n\n<p>It is the view in charge of deleting the records. The reason for inheriting from GenDelete is that the system does certain security checks for record deletion, including permissions and integrity, that Django itself does not. It also responds appropriately to the controllers that deal with the management of the forms.<\/p>\n\n\n\n<p>So far, we have explained everything necessary to operate with the Generic views of <strong><span style=\"color: #343433;\"><strong><a href=\"https:\/\/github.com\/codenerix\/django-codenerix\"><span style=\"color: #343433;\">CODE<\/span><span style=\"color: #70a8e0;\">NERIX<\/span><\/a><\/strong><\/span><\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83c\uddea\ud83c\udde6&nbsp;Leer en Espa\u00f1ol, \u201cGenCreate, GenDetail, GenUpdate y GenDelete\u201c In the last article, we described GenList to start using CODENERIX listings. The time has come to see how to create, view, update and delete the information on those listings. In this article, we will talk about GenCreate, GenDetail, GenUpdate, and GenDelete. First, each one inherits from [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":794,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[20],"tags":[],"class_list":["post-718","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howto"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>GenCreate, GenUpdate, GenDetail and GenDelete - Codenerix<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GenCreate, GenUpdate, GenDetail and GenDelete - Codenerix\" \/>\n<meta property=\"og:description\" content=\"\ud83c\uddea\ud83c\udde6&nbsp;Leer en Espa\u00f1ol, \u201cGenCreate, GenDetail, GenUpdate y GenDelete\u201c In the last article, we described GenList to start using CODENERIX listings. The time has come to see how to create, view, update and delete the information on those listings. In this article, we will talk about GenCreate, GenDetail, GenUpdate, and GenDelete. First, each one inherits from [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/\" \/>\n<meta property=\"og:site_name\" content=\"Codenerix\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-24T08:39:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-06T06:47:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1268\" \/>\n\t<meta property=\"og:image:height\" content=\"845\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Codenerix\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Codenerix\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/\"},\"author\":{\"name\":\"Codenerix\",\"@id\":\"https:\/\/codenerix.com\/#\/schema\/person\/c1dce0f30541a2be119ee8adc332a9af\"},\"headline\":\"GenCreate, GenUpdate, GenDetail and GenDelete\",\"datePublished\":\"2018-03-24T08:39:00+00:00\",\"dateModified\":\"2023-04-06T06:47:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/\"},\"wordCount\":1654,\"image\":{\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png\",\"articleSection\":[\"Howto\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/\",\"url\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/\",\"name\":\"GenCreate, GenUpdate, GenDetail and GenDelete - Codenerix\",\"isPartOf\":{\"@id\":\"https:\/\/codenerix.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png\",\"datePublished\":\"2018-03-24T08:39:00+00:00\",\"dateModified\":\"2023-04-06T06:47:22+00:00\",\"author\":{\"@id\":\"https:\/\/codenerix.com\/#\/schema\/person\/c1dce0f30541a2be119ee8adc332a9af\"},\"breadcrumb\":{\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#primaryimage\",\"url\":\"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png\",\"contentUrl\":\"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png\",\"width\":1268,\"height\":845},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codenerix.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GenCreate, GenUpdate, GenDetail and GenDelete\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codenerix.com\/#website\",\"url\":\"https:\/\/codenerix.com\/\",\"name\":\"Codenerix\",\"description\":\"Framework libre Open Source\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codenerix.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/codenerix.com\/#\/schema\/person\/c1dce0f30541a2be119ee8adc332a9af\",\"name\":\"Codenerix\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codenerix.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dee2772994eb5d89e57afac281bca674800da15c6c32fba528dea162570d644d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dee2772994eb5d89e57afac281bca674800da15c6c32fba528dea162570d644d?s=96&d=mm&r=g\",\"caption\":\"Codenerix\"},\"url\":\"https:\/\/codenerix.com\/en\/author\/codenerix\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GenCreate, GenUpdate, GenDetail and GenDelete - Codenerix","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/","og_locale":"en_US","og_type":"article","og_title":"GenCreate, GenUpdate, GenDetail and GenDelete - Codenerix","og_description":"\ud83c\uddea\ud83c\udde6&nbsp;Leer en Espa\u00f1ol, \u201cGenCreate, GenDetail, GenUpdate y GenDelete\u201c In the last article, we described GenList to start using CODENERIX listings. The time has come to see how to create, view, update and delete the information on those listings. In this article, we will talk about GenCreate, GenDetail, GenUpdate, and GenDelete. First, each one inherits from [&hellip;]","og_url":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/","og_site_name":"Codenerix","article_published_time":"2018-03-24T08:39:00+00:00","article_modified_time":"2023-04-06T06:47:22+00:00","og_image":[{"width":1268,"height":845,"url":"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png","type":"image\/png"}],"author":"Codenerix","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Codenerix","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#article","isPartOf":{"@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/"},"author":{"name":"Codenerix","@id":"https:\/\/codenerix.com\/#\/schema\/person\/c1dce0f30541a2be119ee8adc332a9af"},"headline":"GenCreate, GenUpdate, GenDetail and GenDelete","datePublished":"2018-03-24T08:39:00+00:00","dateModified":"2023-04-06T06:47:22+00:00","mainEntityOfPage":{"@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/"},"wordCount":1654,"image":{"@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#primaryimage"},"thumbnailUrl":"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png","articleSection":["Howto"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/","url":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/","name":"GenCreate, GenUpdate, GenDetail and GenDelete - Codenerix","isPartOf":{"@id":"https:\/\/codenerix.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#primaryimage"},"image":{"@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#primaryimage"},"thumbnailUrl":"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png","datePublished":"2018-03-24T08:39:00+00:00","dateModified":"2023-04-06T06:47:22+00:00","author":{"@id":"https:\/\/codenerix.com\/#\/schema\/person\/c1dce0f30541a2be119ee8adc332a9af"},"breadcrumb":{"@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#primaryimage","url":"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png","contentUrl":"https:\/\/codenerix.com\/wp-content\/uploads\/2018\/03\/codenerix_form-1b.png","width":1268,"height":845},{"@type":"BreadcrumbList","@id":"https:\/\/codenerix.com\/en\/gencreate-genupdate-gendetail-and-gendelete\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codenerix.com\/en\/"},{"@type":"ListItem","position":2,"name":"GenCreate, GenUpdate, GenDetail and GenDelete"}]},{"@type":"WebSite","@id":"https:\/\/codenerix.com\/#website","url":"https:\/\/codenerix.com\/","name":"Codenerix","description":"Framework libre Open Source","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codenerix.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/codenerix.com\/#\/schema\/person\/c1dce0f30541a2be119ee8adc332a9af","name":"Codenerix","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codenerix.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dee2772994eb5d89e57afac281bca674800da15c6c32fba528dea162570d644d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dee2772994eb5d89e57afac281bca674800da15c6c32fba528dea162570d644d?s=96&d=mm&r=g","caption":"Codenerix"},"url":"https:\/\/codenerix.com\/en\/author\/codenerix\/"}]}},"_links":{"self":[{"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/posts\/718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/comments?post=718"}],"version-history":[{"count":15,"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/posts\/718\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/posts\/718\/revisions\/872"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/media\/794"}],"wp:attachment":[{"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/media?parent=718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/categories?post=718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codenerix.com\/en\/wp-json\/wp\/v2\/tags?post=718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}