Created
May 25, 2016 02:00
-
-
Save mkoistinen/4c7ba5e059c6da699f8ca799d357777a to your computer and use it in GitHub Desktop.
Barebones Hostels App and CMSPlugin:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from django.contrib import admin | |
from .models import Hostel, Room | |
class RoomInlineAdmin(admin.TabularInline): | |
model = Room | |
class HostelAdmin(admin.ModelAdmin): | |
inlines = (RoomInlineAdmin, ) | |
admin.site.register(Hostel, HostelAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from cms.plugin_base import CMSPluginBase | |
from cms.plugin_pool import plugin_pool | |
from .models import HostelPluginModel | |
class HostelPlugin(CMSPluginBase): | |
model = HostelPluginModel | |
name = 'Hostel rooms' | |
render_template = 'hostels/plugins/hostel_rooms.html' | |
plugin_pool.register_plugin(HostelPlugin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from django.db import models | |
from django.utils.encoding import python_2_unicode_compatible | |
from cms.models import CMSPlugin | |
@python_2_unicode_compatible | |
class Hostel(models.Model): | |
name = models.CharField(max_length=64) | |
def __str__(self): | |
return self.name | |
@python_2_unicode_compatible | |
class Room(models.Model): | |
name = models.CharField(max_length=64) | |
hostle = models.ForeignKey(Hostel, related_name="rooms") | |
def __str__(self): | |
return self.name | |
@python_2_unicode_compatible | |
class HostelPluginModel(CMSPlugin): | |
hostel = models.ForeignKey(Hostel) | |
def __str__(self): | |
return "Rooms for hostel {0}".format(self.hostel) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>{{ instance.hostel.name }}</h1> | |
<ul> | |
{% for room in instance.hostel.rooms.all %} | |
<li>{{ room.name }}</li> | |
{% empty %} | |
<li>No rooms defined.</li> | |
{% endfor %} | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is possible way to pull data from Db and show in setting fields? Right now I am doing this:
How
CHOICES
can get data from Db and show in Combo?