mirror of
https://github.com/Hopiu/django-markdownx.git
synced 2026-03-16 21:40:24 +00:00
parent
3af00e0b2c
commit
67b1769ebd
12 changed files with 49 additions and 99 deletions
|
|
@ -1,29 +1,7 @@
|
|||
from django.db import models
|
||||
from django.contrib.admin import site, ModelAdmin
|
||||
|
||||
from markdownx.widgets import AdminMarkdownxWidget
|
||||
from markdownx.models import MarkdownxField
|
||||
from django.contrib import admin
|
||||
|
||||
from markdownx.admin import MarkdownxModelAdmin
|
||||
from .models import MyModel
|
||||
|
||||
|
||||
class MyModelAdmin(ModelAdmin):
|
||||
formfield_overrides = {
|
||||
MarkdownxField: {'widget': AdminMarkdownxWidget},
|
||||
models.TextField: {'widget': AdminMarkdownxWidget},
|
||||
}
|
||||
|
||||
|
||||
site.register(MyModel, MyModelAdmin)
|
||||
|
||||
##
|
||||
## SHORTER OPTION:
|
||||
##
|
||||
|
||||
# from django.contrib import admin
|
||||
|
||||
# from markdownx.admin import MarkdownxModelAdmin
|
||||
|
||||
# from .models import MyModel
|
||||
|
||||
# admin.site.register(MyModel, MarkdownxModelAdmin)
|
||||
admin.site.register(MyModel, MarkdownxModelAdmin)
|
||||
|
|
|
|||
|
|
@ -1,18 +1,7 @@
|
|||
from django import forms
|
||||
|
||||
from markdownx.fields import MarkdownxFormField
|
||||
from markdownx.widgets import MarkdownxWidget
|
||||
|
||||
|
||||
class MyForm(forms.Form):
|
||||
markdownx_form_field1 = MarkdownxFormField(
|
||||
widget=MarkdownxWidget(
|
||||
attrs={'class': 'custom-class-markdownx_form_field1'}
|
||||
)
|
||||
)
|
||||
|
||||
markdownx_form_field2 = MarkdownxFormField(
|
||||
widget=MarkdownxWidget(
|
||||
attrs={'class': 'custom-class-markdownx_form_field2'}
|
||||
)
|
||||
)
|
||||
myfield = MarkdownxFormField()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11 on 2017-05-04 20:21
|
||||
# Generated by Django 1.11.1 on 2017-05-11 21:12
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
|
@ -18,10 +18,7 @@ class Migration(migrations.Migration):
|
|||
name='MyModel',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('markdownx_field1', markdownx.models.MarkdownxField()),
|
||||
('markdownx_field2', markdownx.models.MarkdownxField()),
|
||||
('textfield1', models.TextField()),
|
||||
('textfield2', models.TextField()),
|
||||
('myfield', markdownx.models.MarkdownxField()),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,8 +4,4 @@ from markdownx.models import MarkdownxField
|
|||
|
||||
|
||||
class MyModel(models.Model):
|
||||
markdownx_field1 = MarkdownxField()
|
||||
markdownx_field2 = MarkdownxField()
|
||||
|
||||
textfield1 = models.TextField()
|
||||
textfield2 = models.TextField()
|
||||
myfield = MarkdownxField()
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ INSTALLED_APPS = (
|
|||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
'markdownx',
|
||||
'testapp',
|
||||
|
||||
'markdownx',
|
||||
)
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
@ -65,8 +66,6 @@ TEMPLATES = [
|
|||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
|
||||
# list if you haven't customized them:
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.i18n',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,29 @@
|
|||
<!doctype html>
|
||||
<html lang="pl">
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css">
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<nav class="navbar navbar-default">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="{% url 'form_view' %}">Generic Form</a></li>
|
||||
<li><a href="{% url 'admin:index' %}">Django Admin</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<ul>
|
||||
<li><a href="{% url 'form_view' %}">Generic Form</a></li>
|
||||
<li><a href="{% url 'create_view' %}">Generic Create View</a></li>
|
||||
</ul>
|
||||
<form role="form" method="POST" action="">{% csrf_token %}
|
||||
{{ form }}
|
||||
</form>
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
|
|
|||
8
testapp/templates/markdownx/widget2.html
Normal file
8
testapp/templates/markdownx/widget2.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<div class="markdownx row">
|
||||
<div class="col-md-6">
|
||||
{% include 'django/forms/widgets/textarea.html' %}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="markdownx-preview"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<form role="form" method="POST" action="">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
</form>
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<form role="form" method="POST" action="">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
</form>
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
|
|
@ -3,17 +3,11 @@ from django.conf.urls import include, url
|
|||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
|
||||
from testapp.views import (
|
||||
IndexTemplateView,
|
||||
TestFormView,
|
||||
TestCreateView,
|
||||
)
|
||||
from testapp.views import TestFormView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', IndexTemplateView.as_view()),
|
||||
url(r'^form-view/$', TestFormView.as_view(), name='form_view'),
|
||||
url(r'^create-view/$', TestCreateView.as_view(), name='create_view'),
|
||||
url(r'^$', TestFormView.as_view(), name='form_view'),
|
||||
url(r'^markdownx/', include('markdownx.urls')),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
|
|||
|
|
@ -1,27 +1,9 @@
|
|||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import FormView, CreateView
|
||||
|
||||
from testapp.models import MyModel
|
||||
from testapp.forms import MyForm
|
||||
|
||||
|
||||
class IndexTemplateView(TemplateView):
|
||||
template_name = 'index.html'
|
||||
|
||||
|
||||
class TestFormView(FormView):
|
||||
template_name = "test_form_view.html"
|
||||
template_name = "index.html"
|
||||
form_class = MyForm
|
||||
success_url = '/'
|
||||
|
||||
|
||||
class TestCreateView(CreateView):
|
||||
template_name = "test_create_view.html"
|
||||
model = MyModel
|
||||
success_url = '/'
|
||||
fields = [
|
||||
'markdownx_field1',
|
||||
'markdownx_field2',
|
||||
'textfield1',
|
||||
'textfield2'
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue