raagin / django-streamfield Goto Github PK
View Code? Open in Web Editor NEWThis is a simple realisation of StreamField's idea from Wagtail CMS for plain Django admin or with Grappelli skin.
License: Other
This is a simple realisation of StreamField's idea from Wagtail CMS for plain Django admin or with Grappelli skin.
License: Other
Hello! Do you know how to create formatting panel for Streamfield or enable ckeditor for text formatting? I need it for RichText. Here is my code:
class About(models.Model):
stream = StreamField(
model_list=[
RichText,
ImageWithText
],
popup_size=(1000, 500),
verbose_name="Блок обо мне",
)
Thank you for this great package!
Could you add an API integration section in the documentation?
I would like to integrate this package with django-ninja
, but I'm getting the following error:
TypeError: Object of type PageTitle is not JSON serializable
This is my schema:
class PageSchema(Schema):
id: int
stream: List[dict]
def resolve_stream(self, obj):
return obj.stream.as_list()
The StreamField doesn't work in django admin inlines because it's not initializating when a new inline form is added to the inline formset. Maybe the trick is to listen to this event formset:added
and then to do the initialization.
Maybe adding something like this to streamfield_widget.js
can work:
document.addEventListener("formset:added", function(event) {
let app_node = event.target.querySelector('.streamfield_app');
let app = createApp(App, {app_node}).mount(app_node.querySelector('.mount-node'));
window.streamapps[app_node.id] = app;
});
`
When following the documentation, im tryng to add a block to my page programmatically and I get the following error:
AttributeError: 'list' object has no attribute 'add'
This is what im doing:
article = Article()
new_block = Text(text='<p>Hello world</p>')
article.content.add(new_block)
article.save()
I'm following this documentation: https://github.com/raagin/django-streamfield#add-block-programarly
And of course the content is a StreamField:
class Article(models.Model):
...
content = StreamField(model_list=[Text])
Can I use this app together with django-polymorphic app, is it compatible?
Docs: https://django-polymorphic.readthedocs.io/en/stable/index.html
Code: https://github.com/django-polymorphic/django-polymorphic
I have polymorphic-based section models. I would like to attach streamfield to all of them (with different set of available blocks per section type). So user may create section and add some blocks there.
Suggestion also: move all code inside of StreamBlocksAdmin(admin.ModelAdmin)
to StreamBlocksAdminMixin(object)
and add StreamBlocksAdmin(StreamBlocksAdminMixin, admin.ModelAdmin)
.
I'd like to report a bug:
If you created a streamblock without adding content, then deleting it again, trying to save the entity containing the streamfield, it'll still try to delete the not yet created streamblock resulting in a query like this: http://localhost:8000/streamfield/admin-instance/absolutemodifier/-1/delete/
That obiously results in a 404 failing the attempt to save the entity
I got this while I open page of layout page. Seems like ajax issue while getting static js
screenshot
django-streamfield seems not to work with the global setting CSRF_USE_SESSIONS=True (see https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-CSRF_USE_SESSIONS) due to
Adding new blocks or saving changes in blocks in the admin UI works - but saving a model instance after deleting blocks fails with:
Forbidden (403)
CSRF verification failed. Request aborted.
Browser debug console shows:
Uncaught (in promise)
Object { stack: "I@https://www.xxx.xx/static/dde6e8f9/streamfield/streamfield_widget.js:1:261104\n
...
message: "Request failed with status code 403", name: "AxiosError", code: "ERR_BAD_REQUEST", config: {…}, request: XMLHttpRequest, response: {…} }
code: "ERR_BAD_REQUEST"
config: Object { timeout: 0, xsrfCookieName: "XSRF-TOKEN", xsrfHeaderName: "X-XSRF-TOKEN", … }
message: "Request failed with status code 403"
name: "AxiosError"
It would be probably smart if the app can automatically use the cookie name from the settings if possible. Bear in mind that the name of both the CSRF and the Session cookie can be freely configured via Django settings (see https://docs.djangoproject.com/en/5.0/ref/settings/#session-cookie-name and https://docs.djangoproject.com/en/5.0/ref/settings/#csrf-cookie-name)
screenshot
With latest version, I can't add new block. The button is there but nothing is happening
Hello! We love the StreamField in Django but we often find ourselves having to reorder sections in a blog article. Each section usually contains 8-10 different blocks and is extremely time-consuming having to move one by one.
Would it be possible to add the functionality to select and move multiple blocks at once?
Deleting object from streamfield cause ProgrammingError
.
Example traceback:
Traceback (most recent call last):
File ".../site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File ".../site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File ".../site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File ".../site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File ".../site-packages/streamfield/views.py", line 58, in delete_instance
obj = t.get_object_for_this_type(pk=pk)
File ".../site-packages/django/contrib/contenttypes/models.py", line 168, in get_object_for_this_type
return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
...
...
File ".../site-packages/MySQLdb/connections.py", line 254, in query
_mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'accounts.streamblocks_imagewithtext' doesn't exist")
The problem appears, because for my project contenttypes
are in the accounts
database, however streamblocks
models are stored in the default
. The t.get_object_for_this_type
function runs queryset with .using(self._state.db)
, where self._state.db=="accounts"
.
Hi,
thank you for this great package.
The following error is raised when using ManifestStaticFilesStorage
and running python manage.py collectstatic
:
ValueError: The file 'streamfield/vendor/vuedraggable.umd.min.js.map' could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x7f3137437d00>.
The cause is that vuedraggable.umd.min.js
contains a reference to vuedraggable.umd.min.js.map
and django tries to solve but it doesn't find the file:
https://github.com/raagin/django-streamfield/blob/master/streamfield/static/streamfield/vendor/vuedraggable.umd.min.js
Python version: 3.8
Django version: 4.1
Hello! Thanks for this amazing package. I would like to use it for my existing app but this message appears
when I click on post detail page after successfully saving post in admin:
Not Found: /folder/7909375238_n.jpg
I can see my file is saved well in project root's "folder" directory but I don't know why it can't load the image.
Thanks for your help in advance.
This is really great!
I wonder if there is anyway to cleanup orphaned blocks, though. Deleting blocks, or the page, don't delete underlying column or text objects.
I know it's a limitation of streamfield and nosql. However, my users are going to create hundreds/thousands of orphaned blocks, if they have the chance.
It'd also be nice to link to existing blocks.
Why don't retrieve base admin url using reverse('admin:index')
?
In this way it would be possible to remove STREAMFIELD_BASE_ADMIN_URL
setting.
Hello @raagin,
thank you for this great application.
I have some streamblocks models that have not fields (because their template includes another existing template which uses some templatetags), in this case when clicking the "+ Add content" in the backend it results in a 404 error inside the popup.
I think that the right solution is to hide "+ Add content" button if the streamblocks model has not fields.
It is just what I was looking for, but I see that it is only for the django manager, I would like to use it in a django view, or be able to add elements without the manager, I have not seen documentation on this. thank you so much.
I have an Article model looking something like this:
class Article(Model):
title = models.CharField(max_length=255)
content = StreamField(
verbose_name='Blocks',
model_list=[Text, Header, SubHeader, ImageSingle, ImageDouble, Video, InfoBox, MultiUse],
)
Now I want to programmatically create the streamfields and add them to the article
# Create article
article = Article()
article.title = 'This is my title'
#Create text blocks
text1 = RichText(text='<p>This is the first block of text<p>')
text2 = RichText(text='<p>This is the second block of text<p>')
text1.save()
text2.save()
# Add text to article
article.content = [text1, text2] #This doesn't work
article.content.add(text1) # This doesn't work either
article.content.add(text2) # This doesn't work either
# Save article to database
article.save()
How can I programmatically add the streamblocks to the article?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.