file fields

53 views
Skip to first unread message

ايهاب توفيق

unread,
Jan 25, 2017, 6:04:28 PM1/25/17
to Django users
I am new in django and to know how to use multiple file field in the same model can any one help me

ludovic coues

unread,
Jan 26, 2017, 3:09:58 AM1/26/17
to django...@googlegroups.com
If you want a fixed set of file field, you declare multiple file
field, each with a different name. For exemple:

class UserProfile(models.Model):
photo_front = models.FileField(...)
photo_side = models.FileField(...)

If you want a list of photo, you don't know yet how many, you use a
second model with a foreign key:

class UserPhoto(models.Model):
user = models.ForeignKey(UserProfile, models.CASCADE,
related_name="photos")
photo = models.FileField(...)

With the second model, you access all the photo with
user_profile.photos.all(). If the related_name attribute on the
foreign key is "photo_set", user_profile.photo_set.all().

I hope this will help you and that I am clear enough :)

2017-01-26 0:00 GMT+01:00 ايهاب توفيق <e.bug...@gmail.com>:
> I am new in django and to know how to use multiple file field in the same
> model can any one help me
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/da76e41d-1975-4371-b91d-4eedd9ba9a96%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

ايهاب توفيق

unread,
Jan 27, 2017, 5:36:47 PM1/27/17
to Django users

Thank you for your reply and I try the fixed model but the problem with the view that I use to store the files from templets to the db I followed the django documents as

def custmoer(request):
    if request.method == 'POST':
        form = CustomerForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/login/custmoer/')
        else:
            return HttpResponseRedirect('/login')
    else:
        form= CustomerForm()
        return render(request, "custmoer.html", {'form':form})

 this will work if it one file filed but for more than one will give erro I don’t know how to fix this 

ludovic coues

unread,
Jan 28, 2017, 4:11:28 AM1/28/17
to django...@googlegroups.com
The error should give some information on what is going wrong and how to fix it
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9edfcc46-e3e6-4ce7-a7ff-8ca12ed16ec8%40googlegroups.com.

ايهاب توفيق

unread,
Feb 7, 2017, 2:15:57 PM2/7/17
to Django users

this the error that keep coming up TypeError: _getfullpathname: illegal type for path parameter 
بتاريخ الخميس، 26 يناير، 2017 1:04:28 ص UTC+2، كتب ايهاب توفيق:

ludovic coues

unread,
Feb 7, 2017, 2:36:04 PM2/7/17
to django...@googlegroups.com
Can you post the full backtrace ?
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ce05b6ca-a5fa-468e-8230-a501e9239a91%40googlegroups.com.

ايهاب توفيق

unread,
Feb 8, 2017, 7:02:07 PM2/8/17
to Django users
hi this backtrace

Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x036B8588>
Traceback (most recent call last):
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
    self.check_migrations()
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\runserver.py", line 163, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
    self.build_graph()
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\loader.py", line 170, in build_graph
    self.load_disk()
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\loader.py", line 105, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "C:\Users\e.bugaighis\Desktop\ehab\test001\migrations\0007_auto_20161213_1444.py", line 9, in <module>
    class Migration(migrations.Migration):
  File "C:\Users\e.bugaighis\Desktop\ehab\test001\migrations\0007_auto_20161213_1444.py", line 19, in Migration
    field=models.FileField(blank=True, null=True, storage=django.core.files.storage.FileSystemStorage(location=('C:\\Users\\e.bugaighis\\Desktop\\ehab\\media',)), upload_to='/media/'),
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\files\storage.py", line 185, in __init__
    self.location = abspathu(self.base_location)
  File "C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\ntpath.py", line 535, in abspath
    path = _getfullpathname(path)
TypeError: _getfullpathname: illegal type for path parameter

بتاريخ الخميس، 26 يناير، 2017 1:04:28 ص UTC+2، كتب ايهاب توفيق:

ludovic coues

unread,
Feb 12, 2017, 6:14:45 AM2/12/17
to django...@googlegroups.com
Ok, sorry for the delayed response, I was a bit busy the last few days

The error is the location argument for your FileSystemStorage. It
should be a string and you are passing a tuple. That's why you get a
TypeError with illegal type for parameter.
Have you tried to entirely remove the storage argument to your
models.FileField ? By default, upload_to refer to a subfolder of
MEDIA_ROOT, which you can specify in you settings.py file.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/99a9c6a2-2019-4b71-8542-1710bb9ebff7%40googlegroups.com.

ايهاب توفيق

unread,
Feb 18, 2017, 9:56:25 AM2/18/17
to Django users
thank you for your help I solve the problem and it working

بتاريخ الخميس، 26 يناير، 2017 1:04:28 ص UTC+2، كتب ايهاب توفيق:
Reply all
Reply to author
Forward
0 new messages