Ahmed Khairy
unread,May 9, 2020, 10:43:42 AM5/9/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
I created an app called marketing app which customizes messages to be written on top of website page. My problem is that these messages are not showing when everything is configured and I don't know why is that might be the template because {{ marketing_message.message}} is only not showing
This is the model of the Marketing App
class MarketingMessage(models.Model):
message = models.CharField(max_length=120)
active = models.BooleanField(default=False)
featured = models.BooleanField(default=False)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
start_date = models.DateTimeField(
auto_now_add=False, auto_now=False, null=True, blank=True)
end = models.DateTimeField(
auto_now_add=False, auto_now=False, null=True, blank=True)
def __str__(self):
return str(self.message[:12])
this is the views for the core app:
class HomeView(ListView):
model = Item
paginate_by = 10
template_name = "home.html"
def get_context_data(self, **kwargs):
context = super(HomeView, self).get_context_data(**kwargs)
context['marketing_message'] = MarketingMessage.objects.all()
this is the template:
{% if marketing_message %}
<div class="alert alert-light" style="padding-top:80px; margin-bottom:-24px">
<a href="#" class="close" data-dismiss="alert">×</a>
<div class="container" style="text-align:center">
<strong>Marketing Message ! : </strong> {{ marketing_message.message}}
</div>
</div>
{% endif %}
This is the admin.py of marketing
from django.contrib import admin
from .models import MarketingMessage
# Register your models here.
class MarketingMessageAdmin(admin.ModelAdmin):
class Meta:
model = MarketingMessage
admin.site.register(MarketingMessage, MarketingMessageAdmin)
return context