1
What are the steps for creating a class diagram of a project made with Django? How can I represent MVC in the diagram? My project has only one Post class:
from django.db import models
from django.utils import timezone
class Post(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length = 250)
content = models.TextField()
published_date = models.DateTimeField(blank = True, null = True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
I also created the following views:
from django.shortcuts import render
from django.utils import timezone
from .models import Post
from django.shortcuts import render, get_object_or_404
from .forms import PostForm
from django.shortcuts import redirect
def post_list(request):
posts = Post.objects.filter(published_date__lte = timezone.now()).order_by('published_date').reverse()
return render(request, 'blog/post_list.html', {'posts': posts})
def post_detail(request, pk):
post = get_object_or_404(Post, pk=pk)
return render (request, 'blog/post_detail.html', {'post': post})
def post_new(request):
if request.method == "POST":
form = PostForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.author = request.user
post.published_date = timezone.now()
post.save()
return redirect('blog.views.post_list')
else:
form = PostForm()
return render(request, 'blog/post_create.html', {'form': form})
def post_edit(request, pk):
post = get_object_or_404(Post, pk=pk)
if request.method == "POST":
form = PostForm(request.POST, instance=post)
if form.is_valid():
post = form.save(commit=False)
post.author = request.user
post.save()
return redirect('blog.views.post_detail', pk=post.pk)
else:
form = PostForm(instance=post)
return render(request, 'blog/post_edit.html', {'form': form})
def post_delete(request, pk):
post = get_object_or_404(Post, pk=pk)
post.delete()
return render(request, 'blog/post_delete.html')
Can you post the codes instead of the image? Help to those who can help you.
– Florida
@Florida Sorry, already edited with the codes used.
– Erick
I think your question is a little wrong. "What are the steps for creating a class diagram for a project made with Django? " A class diagram can be implemented in any object-oriented language. You do an analysis of your case study, do the diagrams and AFTER you program. Whether it’s in Django, java, php or whatever. Study some UML. This will help you in creating the class diagram.
– Puam Dias
You should create your template initially independent of frameworks.. Your model should be the core of your system, initially using class diagram or other ( activity , flowchart ) with your model ready, then yes you can port it to any frameworks..
– Marlysson