User Tools

Site Tools


programming:django

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programming:django [2019/03/22 15:17] clemixprogramming:django [2019/04/24 16:22] (current) – [Static files] clemix
Line 133: Line 133:
 </code> </code>
  
-==== Mixed in for django_tables2 ====+Run this command to store static files in proper folder: 
 +<code bash> 
 +python manage.py collectstatic 
 +</code> 
 +==== django_tables2 ==== 
 +=== Mixedin ===
  
 <code python> <code python>
Line 153: Line 158:
 </code> </code>
  
-To make links of a value https://django-tables2.readthedocs.io/en/latest/pages/api-reference.html?highlight=LinkColumn#django_tables2.columns.LinkColumn+===  Custom tables.Column === 
 +<code python> 
 +class AgeColumn(tables.Column): 
 +    def render(self, record): 
 +        diff = record.age() 
 +        color '' 
 +        if (diff.seconds > 60 * 60 ): 
 +            color = 'red' 
 +        else: 
 +            color = 'green' 
 +        return format_html('<span style="color:{}">{}</span>',color, diff)
  
 +
 +class InstanceTable(tables.Table):
 +    age = AgeColumn()
 +    opt = tables.LinkColumn('delete_instance', args=[A('pk')], text='delete')
 +    class Meta:
 +        model = Instance
 +        template_name = 'django_tables2/bootstrap.html'
 +</code>
 +
 +To make links of a value https://django-tables2.readthedocs.io/en/latest/pages/api-reference.html?highlight=LinkColumn#django_tables2.columns.LinkColumn
 ==== Update database ==== ==== Update database ====
 Change the model file accordingly. [[https://docs.djangoproject.com/en/2.1/ref/django-admin/#makemigrations|doc:makemigrations]] Change the model file accordingly. [[https://docs.djangoproject.com/en/2.1/ref/django-admin/#makemigrations|doc:makemigrations]]
Line 161: Line 186:
 python manage.py migrate python manage.py migrate
 </code> </code>
 +
 +==== Bootstrap ====
 +https://www.w3schools.com/bootstrap/default.asp
  
  
programming/django.1553264229.txt.gz · Last modified: by clemix

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki