Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editare martor form afisand continutul existent in DB #11

Closed
ionescu77 opened this issue Jun 19, 2020 · 3 comments
Closed

Editare martor form afisand continutul existent in DB #11

ionescu77 opened this issue Jun 19, 2020 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed

Comments

@ionescu77
Copy link
Collaborator

ionescu77 commented Jun 19, 2020

  1. In views.py
    Cand instantiezi PostForm() ii trimiti informatia deja existenta PostForm(news.body)
def news_edit(request,pk):
    news = News.objects.get(pk=pk)
    category = SubCategory.objects.all()
    form = PostForm(some_body=news.body)
    if request.method == 'POST':
        newstitle = request.POST.get('newstitle')
        newscategory = request.POST.get('newscategory')
        newssummary = request.POST.get('newssummary')
        newsbody = request.POST.get('body')
        newsid = request.POST.get('newscategory')
  1. Informs.py
    Faci "override" cand se initializeaza PostForm cu __init__ si:
  • extragi informatia din views.py cu kwargs.pop('some_body', None)
  • apoi daca ai primit informatie setezi form field-ul body folosind .initial
from django import forms

from martor.fields import MartorFormField
from .models import News


class SimpleForm(forms.Form):
    body = MartorFormField()


class PostForm(forms.ModelForm):
    class Meta:
        model = News
        fields = '__all__'
    def __init__(self, *args, **kwargs):
        # Aici initializam form-ul cu some_body
        # primit din views.py news_edit
        body = kwargs.pop('some_body', None)
        super(PostForm, self).__init__(*args, **kwargs)
        if body:
            self.fields['body'].initial = body
@ionescu77
Copy link
Collaborator Author

O sa salvez branch-ul meu.

Dar te rog experimenteaza si make it work ca erai aproape.

@ionescu77 ionescu77 added documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed labels Jun 19, 2020
@ionescu77
Copy link
Collaborator Author

M-am inspirat din issue mai vechi la martor, apoi a trebuit sa studiez un pic sa imi amintesc cum poti transmite informatia din view.py catre un forms.py

Practic trebuie sa initializezi formul cu valoarea (cum face martot in admin):

agusmakmun/django-markdown-editor#32

Ceva in genul asta

https://stackoverflow.com/questions/1993014/passing-kwargs-to-django-form

@Dominiq97
Copy link
Owner

bd2cb7b
Multumesc mult, acum m-am prins cum merge si treaba cu kwargs

Am creat un nou branch Martor-Original plus ca

Se poate face live markdown din editarea setarilor
a4eb19a

Deci o noua modalitate de a avea si markdownX dar mai usor de implementat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants