I'm creating a basic CMS. The CMS will contain information about different 
Entities.


A normal users can only see the information about the Entities but an 
editor will have access to an Dashboard were it can add new Entities or 
updated them.

I have an app Entity that use class-based view (CBV) for 
create,update,details,list-display (CRUD).


The urls for listing and details are: /entities and /entity-name


Because update and create are behind login and use different urls I create 
a second app Dashboard that use the create/update models of the Entity app


The urls are account/add and account/edit. 


*There is another solution to have different urls for views of the same 
model ?*


I want the fist page of the dashboard to show different information based 
on the following logic(exist and/or is activated): 

   - if doesn't exist I want the CreateView (CBV) and corresponding form to 
   appear
   - if exist but it is not active a Pending message
   - if exists and active the data of the entity

I can do the logic at the template level, but to separate things is better 
to be done at the CBV level. So in this case I need some help, how to 
implement it.


The Entity is in OneToOne Relationship with User.


I use EntityMixin to check if the user is login and get the corresponding 
entity.


Enter code here...

class EntityCreateView(EntityMixin, CreateView):

model = Entity
form_class = EntityModelForm

def get(self, request, *args, **kwargs):

    entity = self.get_entity()

    # declare context
    context = {}

    # if entity found/exist we get the active(Boolean)attribute value/status
    if entity:
        is_active = entity.active

        if is_active:
            context['title'] = 'Dashboard'
            context['entity'] = self.get_entity()


        else:
            context['title'] = 'Entity Pending'

    else:

            context['title'] = 'Add Entity'
            context['add_entity_form'] = EntityModelForm

    return render(request, 'accounts/dashboard.html', context)



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4b78d042-3bda-416a-987c-9c1b6e132dcc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to