mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Add 'user' field to attachment
This commit is contained in:
21
InvenTree/stock/migrations/0037_stockitemattachment_user.py
Normal file
21
InvenTree/stock/migrations/0037_stockitemattachment_user.py
Normal file
@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.0.5 on 2020-05-12 10:33
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('stock', '0036_stockitemattachment'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='stockitemattachment',
|
||||
name='user',
|
||||
field=models.ForeignKey(blank=True, help_text='User', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
@ -193,6 +193,16 @@ class LocationSerializer(InvenTreeModelSerializer):
|
||||
class StockItemAttachmentSerializer(InvenTreeModelSerializer):
|
||||
""" Serializer for StockItemAttachment model """
|
||||
|
||||
def __init_(self, *args, **kwargs):
|
||||
user_detail = kwargs.pop('user_detail', False)
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if user_detail is not True:
|
||||
self.fields.pop('user_detail')
|
||||
|
||||
user_detail = UserSerializerBrief(source='user', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = StockItemAttachment
|
||||
|
||||
@ -200,7 +210,9 @@ class StockItemAttachmentSerializer(InvenTreeModelSerializer):
|
||||
'pk',
|
||||
'stock_item',
|
||||
'attachment',
|
||||
'comment'
|
||||
'comment',
|
||||
'user',
|
||||
'user_detail',
|
||||
]
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
<tr>
|
||||
<th data-field='file' data-searchable='true'>{% trans "File" %}</th>
|
||||
<th data-field='comment' data-searchable='true'>{% trans "Comment" %}</th>
|
||||
<th data-field='user' data-searchable='true'>{% trans "Uploaded By" %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -30,6 +31,9 @@
|
||||
<tr>
|
||||
<td><a href='/media/{{ attachment.attachment }}'>{{ attachment.basename }}</a></td>
|
||||
<td>{{ attachment.comment }}</td>
|
||||
<td>
|
||||
{% if attachment.user %}{{ attachment.user.username }}{% else %}-{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div class='btn-group' style='float: right;'>
|
||||
<button type='button' class='btn btn-default btn-glyph attachment-edit-button' url="{% url 'stock-item-attachment-edit' attachment.id %}" data-toggle='tooltip' title='{% trans "Edit attachment" %}'>
|
||||
|
@ -160,6 +160,12 @@ class StockItemAttachmentCreate(AjaxCreateView):
|
||||
ajax_form_title = _("Add Stock Item Attachment")
|
||||
ajax_template_name = "modal_form.html"
|
||||
|
||||
def post_save(self, **kwargs):
|
||||
""" Record the user that uploaded the attachment """
|
||||
|
||||
self.object.user = self.request.user
|
||||
self.object.save()
|
||||
|
||||
def get_data(self):
|
||||
return {
|
||||
'success': _("Added attachment")
|
||||
|
Reference in New Issue
Block a user